KnowledgeBoat Logo
OPEN IN APP

Chapter 3

Getting Started with Python

Class 11 - Computer Science with Python Preeti Arora



Fill in the Blanks

Question 1

Programs are a set of instructions given to the computer to solve a problem.

Question 2

A/An Algorithm is defined as a finite sequence of steps required to get the desired output.

Question 3

A Flowchart is a type of diagram that represents the algorithm graphically using boxes of various types, connected by arrows.

Question 4

Python was created by Guido Van Rossum.

Question 5

Python is called a/an interpreted language.

Question 6

Python syntax is Case-Sensitive.

Question 7

In Python, a syntax error is detected by the interpreter at runtime.

Question 8

Python is a/an platform independent language.

Question 9

To start Python from the command prompt, use the python command.

Question 10

Python programs are saved using the .py or .pyw extension.

Question 11

Python programming can be done in interactive and script modes.

Question 12

There are no standard rules to write Pseudocode.

Question 13

An Algorithm is the process to write step-wise solution of a given problem in English-like language.

Question 14

Decomposition is the process of breaking down a complex problem into smaller problems so that they can be managed easily.

Question 15

print() is defined as an output statement to display the result of a code on the output screen.

State True or False

Question 1

Breaking down a complex problem into smaller parts is called decomposition.

Answer

True

Reason — Decomposition is the process of breaking down a complex problem or system into smaller, easily manageable parts.

Question 2

Pseudocode is the pictorial representation of an algorithm.

Answer

False

Reason — Flowchart is the pictorial representation of step-by-step solution to a given problem. While, pseudocode is a simple and informal way of writing programming code in English.

Question 3

Python is a dynamically typed language.

Answer

True

Reason — Python is a dynamically typed language because variables do not need to be declared with a specific type. Instead, the type of a variable is determined at runtime based on the value assigned to it.

Question 4

Alt+R is used to repeat the last typed command in Python shell.

Answer

False

Reason — For repeating or recalling the last command in the Python shell, the correct key is the up arrow key (↑).

Question 5

Print and print are same in Python.

Answer

False

Reason — In Python, print and Print are not the same because Python is a case-sensitive language.

Question 6

The sep argument is used with print() method.

Answer

True

Reason — The sep argument in the print() function is used to specify a string that separates the objects being printed. The default separator is a space.

Question 7

Python is a compiled high-level language.

Answer

False

Reason — Python is an interpreted high-level language.

Question 8

Python is a cross-platform language.

Answer

True

Reason — Python is a cross-platform language because it can run on various operating systems, such as Windows, macOS, Linux, etc.

Question 9

The default extension of Python program file is *.pyt.

Answer

False

Reason — The default extension of Python program file is .py or .pyw.

Question 10

Python Editor refers to Script mode in Python.

Answer

True

Reason — Python Editor refers to a mode in IDLE where we can write and run Python scripts, also known as Script mode.

Question 11

Ctrl+Q shortcut key combination is used to exit Python.

Answer

True

Reason — Ctrl+Q shortcut key combination is used to exit Python.

Question 12

Python code can run on a variety of platforms.

Answer

True

Reason — Python is platform independent and can run across different operating systems/platforms like Windows, Linux/Unix, macOS and other operating Systems.

Question 13

A rectangle represents a process in a flow chart diagram.

Answer

True

Reason — In a flowchart diagram, a rectangle is used to represent a process step.

Multiple Choice Questions

Question 1

What is an algorithm?

  1. A set of steps to solve a problem
  2. Software that analyzes data
  3. A hardware device that stores data
  4. All of these

Answer

A set of steps to solve a problem

Reason — A finite sequence of steps required to get the desired output is called an algorithm.

Question 2

What shape represents a decision in a flow chart?

  1. Diamond
  2. Rectangle
  3. Oval
  4. Parallelogram

Answer

Diamond

Reason — Diamond represents decision/condition in a flow chart.

Question 3

Python was developed by ............... .

  1. Charles Babbage
  2. Guido van Rossum
  3. Tim Berners Lee
  4. Robert E. Kahn

Answer

Guido van Rossum

Reason — Python was developed by Guido van Rossum.

Question 4

You don't have to pay for Python and you can view its source code too. It means Python is-

  1. Freeware
  2. Free and Open source
  3. Open source
  4. Shareware

Answer

Free and Open source

Reason — Python is both free and open-source, meaning it is available for free and its source code can be viewed, modified, and distributed by anyone.

Question 5

Identify the correct print() statement:

  1. print(Hello)
  2. print("Hello")
  3. print('Hello")
  4. print("Hello')

Answer

print("Hello")

Reason — In Python, when using the print() function, strings must be enclosed in matching pairs of either single (') or double quotes ("). Therefore, the correct statement is print("Hello").

Question 6

Python is a/an ............... language.

  1. Compiled
  2. Interpreted
  3. Compiled & Interpreted
  4. None of these

Answer

Interpreted

Reason — Python is an interpreted language. This means that Python code is executed line by line at runtime by an interpreter, without the need for a separate compilation step to machine code.

Question 7

The interactive interpreter of Python is termed as ............... .

  1. Python shell
  2. Python Script mode
  3. Python Editor mode
  4. Python command line

Answer

Python shell

Reason — The interactive interpreter of Python is termed as Python shell.

Question 8

The three greater than signs (>>>) are called the Python ............... .

  1. Cursor
  2. Command prompt
  3. Pointer
  4. Blinking cursor

Answer

Command prompt

Reason — The three greater than signs (>>>) are called the Python command prompt or interactive prompt.

Question 9

Which of the following codes is correct?

1.

print("Programming is fun")
print("Python") 
print("Computer Science")

2.

print ("Programming is fun)
print("Python") 
print("Computer Science)

3.

Print("Programming is fun")
print("Python") 
print("Computer Science")

4.

Print("Programming is fun")
Print("Python") 
Print("Computer Science")

Answer

print("Programming is fun")
print("Python") 
print("Computer Science")

Reason — In Python, the print() function is written in lowercase (print) and strings must be enclosed in matching pairs of either single (') or double quotes ("). Therefore, the correct code would be :

print("Programming is fun")
print("Python") 
print("Computer Science")

Question 10

Python is a case-sensitive language. This means ............... .

  1. Capital and small letters are same for Python
  2. Python doesn't care about the case of alphabets
  3. Python treats capital and small letters as different
  4. Python automatically capitalizes the small letters

Answer

Python treats capital and small letters as different

Reason — Python is a case-sensitive language. This means that Python differentiates between capital and small alphabets.

Question 11

For which set of values will the Python code (s = (a**4) + 5*5**(b + b)) give the output as: 141?

  1. a = 1, b = 2
  2. a = 3, b = 2
  3. a = 2, b = 1
  4. a = 3, b = 1

Answer

a = 2, b = 1

Reason — For a=2, b=1:

s = (24) + 5 * (52) = 16 + 5*25 = 16 + 125 = 141

Question 12

............... mode of Python gives instant result of typed statement.

  1. Interactive mode
  2. Script mode
  3. Both Interactive and Script mode
  4. None of these

Answer

Interactive mode

Reason — Interactive mode of Python gives instant result of typed statement.

Assertions and Reasons

Question 1

Assertion (A): Python is a cross-platform language.

Reasoning (R): Python code can run on a variety of platforms which makes programs very portable as any program written in one platform can easily be used on another.

  1. Both A and R are true and R is the correct explanation of A.
  2. Both A and R are true but R is not the correct explanation of A.
  3. A is true but R is false.
  4. A is false but R is true.

Answer

Both A and R are true and R is the correct explanation of A.

Explanation
Python is a cross-platform language, meaning it is platform-independent and can run across different operating systems such as Windows, Linux/Unix, macOS, and others. Python's ability to execute on various platforms enhances the portability of its programs, allowing the same code to be used across different environments without modification.

Question 2

Assertion (A): Python comes with its own IDLE.

Reasoning (R): IDLE is Python's Integrated Development and Learning Environment which allows programmers to easily write, modify and execute Python programs.

  1. Both A and R are true and R is the correct explanation of A.
  2. Both A and R are true but R is not the correct explanation of A.
  3. A is true but R is false.
  4. A is false but R is true.

Answer

Both A and R are true and R is the correct explanation of A.

Explanation
Python comes with its own IDLE, which is included with Python installations. IDLE is a simple Integrated Development and Learning Environment; it is a program that allows the user to edit, run, browse and debug a Python program from a single interface.

Question 3

Assertion (A): The interactive mode of Python gives instant result of the typed statement.

Reasoning (R): Script mode is an interactive window where Python code can be executed in the same window.

  1. Both A and R are true and R is the correct explanation of A.
  2. Both A and R are true but R is not the correct explanation of A.
  3. A is true but R is false.
  4. A is false but R is true.

Answer

A is true but R is false.

Explanation
The interactive mode of Python gives instant results for typed statements. The Python Shell is an interactive window where you can type in Python code and see the output immediately in the same window. It serves as an interface between Python commands and the operating system.

Question 4

Assertion (A): Python uses an interpreter to convert source code to object code.

Reasoning (R): Python interpreter scans and translates the whole program into machine code in one go.

  1. Both A and R are true and R is the correct explanation of A.
  2. Both A and R are true but R is not the correct explanation of A.
  3. A is true but R is false.
  4. A is false but R is true.

Answer

A is true but R is false.

Explanation
Python uses an interpreter to convert source code into object code. The Python interpreter does not scan and translate the whole program into machine code in one go. Instead, it interprets the code line by line, converting each line into machine code and executing it immediately.

Question 5

Assertion (A): To print the value of a variable, Python uses print() method.

Reasoning (R): print() method displays the content on the system screen or console.

  1. Both A and R are true and R is the correct explanation of A.
  2. Both A and R are true but R is not the correct explanation of A.
  3. A is true but R is false.
  4. A is false but R is true.

Answer

Both A and R are true and R is the correct explanation of A.

Explanation
The print() function is a built-in function in Python that displays the content on the system screen or console. To print the value of a variable, Python uses the print() function.

Question 6

Assertion (A): The shortcut key to run a Python program from script mode is F1.

Reasoning (R): Python programs/scripts are stored in files with .py extension.

  1. Both A and R are true and R is the correct explanation of A.
  2. Both A and R are true but R is not the correct explanation of A.
  3. A is true but R is false.
  4. A is false but R is true.

Answer

A is false but R is true.

Explanation
The shortcut key to run a Python program from script mode is F5. Python programs/scripts are stored in files with .py or .pyw extension.

Question 7

Assertion (A): Python is the fastest language.

Reasoning (R): Python is an interpreted language.

  1. Both A and R are true and R is the correct explanation of A.
  2. Both A and R are true but R is not the correct explanation of A.
  3. A is true but R is false.
  4. A is false but R is true.

Answer

A is false but R is true.

Explanation
Python is not considered the fastest programming language as it is slower than many compiled languages such as C or C++ because it is interpreted rather than compiled. Python is an interpreted language, which means that Python code is executed line by line at runtime by an interpreter, without the need for a separate compilation step to machine code.

Question 8

Assertion (A): Python is a case-sensitive language.

Reasoning (R): Python is easy to understand as it has a clearly defined syntax and simple structure.

  1. Both A and R are true and R is the correct explanation of A.
  2. Both A and R are true but R is not the correct explanation of A.
  3. A is true but R is false.
  4. A is false but R is true.

Answer

Both A and R are true but R is not the correct explanation of A.

Explanation
Python is a case-sensitive language. This means that Python differentiates between capital and small alphabets. Python programs use clear, simple, concise instructions and clearly defined syntax and simple structure that are easy to read and understand even by non-programmers.

Solutions to Unsolved Questions

Question 1

Python is free and open-source. What do you understand by this feature?

Answer

Python is free and open-source means that it is available to anyone at no cost, and its source code can be freely accessed, modified, and distributed by anyone.

Question 2

Write some limitations of Python.

Answer

Some limitations of Python programming language are:

  1. Not the Fastest Language — As Python is an interpreted language so its execution-times are not that fast compared to some compiled languages.
  2. Lesser Libraries than C, Java, Perl — Library collection of C, Java, Perl is better than Python.
  3. Not strong on Type-Binding — Python interpreter is not very strong on catching 'Type-Mismatch' issues.
  4. Not easily convertible — Translating Python programs to other languages is difficult due to its lack of syntax.

Question 3

What is the difference between Script mode and Interactive mode in Python?

Answer

In script mode, we write a Python program in a file and execute it to display the output and in interactive mode, we use the Python prompt '>>>' to start typing commands and see immediate output.

Question 4

Differentiate between flow chart and algorithm.

Answer

Flow chartAlgorithm
A flow chart is defined as a visual representation of the sequence of steps and decisions needed to perform a process/task.A finite sequence of steps required to get the desired output is called an algorithm.
In the flowchart, symbols/shapes are used.In the algorithm, plain text is used.

Question 5

Write a pseudocode that reads two numbers and divide one by another and display the quotient.

Answer

Step 1: INPUT num1
Step 2: INPUT num2
Step 3: IF num2 == 0 THEN
    Step 4: PRINT "Error: Division by zero is not allowed."
ELSE
    Step 5: COMPUTE quotient = num1 / num2
    Step 6: PRINT quotient

Question 6

Two friends decide who gets the last slice of a cake by flipping a coin five times. The first person to win three flips wins the cake. An input of 1 means player 1 wins a flip, and a 2 means player 2 wins a flip. Design an algorithm to determine who takes the cake?

Answer

Step 1: Initialize Counters:

SET p1 = 0
SET p2 = 0

Step 2: Process Coin Flips:

    FOR each flip from 1 to 5
        INPUT result
        IF result is 1 THEN
            INCREMENT p1
        ELSE IF result is 2 THEN
            INCREMENT p2
        IF p1 is 3 THEN
            PRINT "Player 1 wins the cake."
            EXIT the algorithm
        ELSE IF p2 is 3 THEN
            PRINT "Player 2 wins the cake."
            EXIT the algorithm

Question 7

Write a pseudocode to print all multiples of 5 between 10 and 25 (including both 10 and 25).

Answer

Step 1: SET start = 10
Step 2: SET end = 25
Step 3: FOR num = start TO end
    Step 4: IF num MOD 5 is 0 THEN
        Step 5: PRINT num

Question 8

Write a pseudocode that will perform the following:

(a) Read the marks of three subjects: Computer Science, Mathematics and Physics out of 100.

(b) Calculate the aggregate marks.

(c) Calculate the percentage of marks.

Answer

Step 1: Input the marks in Computer Science
Step 2: Input the marks in Mathematics
Step 3: Input the marks in Physics
Step 4: Set total marks by adding marks in Computer Science, Mathematics and Physics
Step 6: Set percentage by dividing total marks by 300 and then multiply it by 100
Step 7: Display total marks and percentage

Question 9

Write an algorithm to find the greatest among two different numbers entered by the user.

Answer

Step 1: 

INPUT number1
INPUT number2

Step 2: 

IF number1 > number2 THEN
    PRINT "The greatest number is: " + number1
ELSE
    PRINT "The greatest number is: " + number2

Step 3: END

Question 10

Write an algorithm that performs the following:

Ask a user to enter a number.
If the number is between 5 and 15, write the word GREEN.
If the number is between 15 and 25, write the word BLUE.
If the number is between 25 and 35, write the word ORANGE.
If it is any other number, write that ALL COLORS ARE BEAUTIFUL.

Answer

Step 1: INPUT number

Step 2:

IF number is between 5 and 15 THEN
    PRINT "GREEN"
ELSE IF number is between 15 and 25 THEN
    PRINT "BLUE"
ELSE IF number is between 25 and 35 THEN
    PRINT "ORANGE"
ELSE
    PRINT "ALL COLORS ARE BEAUTIFUL"

Question 11

Write an algorithm that accepts four numbers as input and find the largest and smallest of them.

Answer

Step 1: INPUT num1, num2, num3, num4

Step 2: SET largest = num1
Step 3: SET smallest = num1

Step 4: IF num2 > largest THEN
            Step 5: SET largest = num2
        ELSE IF num2 < smallest THEN
            Step 6: SET smallest = num2

Step 7: IF num3 > largest THEN
            Step 8: SET largest = num3
        ELSE IF num3 < smallest THEN
            Step 9: SET smallest = num3

Step 10: IF num4 > largest THEN
            Step 11: SET largest = num4
        ELSE IF num4 < smallest THEN
            Step 12: SET smallest = num4

Step 13: PRINT "The largest number is: " + largest
Step 14: PRINT "The smallest number is: " + smallest

Question 12

"Decomposition leads to simplicity." How?

Answer

Decomposition is the process of breaking down a complex problem or system into smaller, easily manageable parts. These smaller problems are solved one after the other until the bigger complex problem is resolved. This stage involves breaking down the problem into smaller components so that they can be tackled more easily. The more we can break down a problem, the easier it is to solve.

Question 13

Write an algorithm to find a factorial of an inputted number.

Answer

Step 1: Start

Step 2: Input the number "n" from the user.

Step 3: Initialize a variable "fact" to 1.

Step 4: If n is 0, then the factorial is 1 and go to Step 7.

Step 5: If "n" is greater than 0, multiply "fact" by each integer from 1 to "n" in sequence.

Step 6: The final value of "fact" is the result.

Step 7: Display "fact".

Step 8: End

Question 14

Match the pairs:

Match the pairs: Getting Started with Python, Computer Science with Python Preeti Arora Solutions CBSE Class 11.

Answer

The matched pairs are given below:

Match the pairs: Getting Started with Python, Computer Science with Python Preeti Arora Solutions CBSE Class 11.

Question 15

Write the pseudocode to print the bill depending upon the price and quantity of an item. Also, print Bill GST, which is the bill after adding 5% tax in the total bill.

Answer

Step 1: INPUT price
Step 2: INPUT quantity

Step 3: COMPUTE total_bill = price * quantity

Step 4: COMPUTE gst_amount = total_bill * 0.05

Step 5: COMPUTE bill_with_gst = total_bill + gst_amount

Step 6: PRINT "Total Bill: ₹" + total_bill
Step 7: PRINT "Bill with GST: ₹" + bill_with_gst

Question 16

When was Python released?

Answer

Python was released in February 1991.

Question 17

Who developed Python and which two languages contributed to Python as a programming language?

Answer

Guido Van Rossum is the developer of Python. ABC language and Modula-3 contributed to Python as a programming language.

Question 18

Is Python case-sensitive?

Answer

Yes, Python is a case-sensitive language. This means that Python differentiates between uppercase (capital) and lowercase (small) letters.

Question 19

What is IDLE?

Answer

IDLE is a simple Integrated Development and Learning Environment that comes with Python. The most important feature of IDLE is that it is a program that allows the user to edit, run, browse and debug a Python program from a single interface.

Question 20

Differentiate between displaying and printing method in Python.

Answer

Printing in Python refers to using the print() function to output information to the console. The print() function takes one or more arguments, converts each argument to a string (if necessary), and displays them as text. On the other hand, displaying can be a more general term that encompasses presenting information or output in various forms, not limited to just text output in the console.

Question 21

Briefly explain the salient features of Python.

Answer

The salient features of Python are as follows:

  1. Python is an interpreted, interactive, directly executed language with a pre-compiled code. This means that it is processed at runtime by the interpreter and we need not compile our program before executing it.
  2. It is a loosely type object-oriented programming language with a few keywords, simple English-like structure and is easy to learn.
  3. It is a free, open-source and portable language having a large repository of libraries.
  4. It takes less time to develop as Python programs are typically 3 to 5 times shorter than the equivalent programming languages. This is because of its built-in, high-level data types and its dynamic typing.
  5. It is extensible/extendable and highly efficient as there is no wastage of time in declaring the types of variables or arguments.
  6. It supports GUI (Graphical User Interface) and garbage collection (better memory management).
  7. It is easily compatible with other languages like C, C++, Core Java etc.
  8. Python is used for both scientific and non-scientific programming.

Question 22

What do you understand by cross-platform software with respect to Python?

Answer

Python is platform-independent and a cross-platform language because it can run on various operating systems, such as Windows, macOS, Linux etc.

Question 23

What are the advantages of Python programming language?

Answer

Advantages of Python programming language are:

  1. Easy to Use — Python is compact, programmer-friendly and very easy to use object oriented language with very simple syntax rules.
  2. Expressive Language — Python is an expressive language, it takes fewer lines of codes to represent the same syntax.
  3. Interpreted Language — Python is an interpreted language, not a compiled language. It makes Python an easy-to-debug language and thus suitable for beginners to advanced users.
  4. Completeness — Python has a rich standard library that provides modules for most types of required functionality like emails, web-pages, databases, GUI development, network connections, etc.
  5. Cross-platform Language — Python can run equally well on variety of platforms — Windows, Linux/UNIX, Macintosh, supercomputers, smart phones, etc.
  6. Free and Open Source — Python language is freely available along with its source-code.
  7. Variety of Usage/Applications — Python has evolved into a powerful, complete and useful language over these years. These days Python is being used in many diverse fields/applications, some of which are Scripting, Web Applications, Game development, Database Applications, System Administrations, Rapid Prototyping, GUI Programs.

Question 24

In how many different ways can you work in Python?

Answer

We can work in Python in two ways:

  1. Interactive mode (also called Immediate mode)
  2. Script mode

Question 25

What are the advantages/disadvantages of working in Interactive mode in Python?

Answer

Interactive mode is useful for testing code. We can type the commands one by one and get the result of error immediately for each command. Disadvantages of Interactive mode are that it does not save commands in form of a program and also output is sandwiched between commands.

Question 26

Write instructions to the Interactive mode for the following:

(a) To display sum of 3, 8.0, 6 * 12

(b) To print sum of 16, 5.0, 44.0

Answer

(a)

>>> 3 + 8.0 + 6 * 12

(b)

>>> print(16 + 5.0 + 44.0)

Question 27

Write the given instructions in Interactive and Script modes to get the following result:

Python is easy to learn and write.  
It allows us to work in two modes: Interactive mode and Script mode.  
Interactive mode is also known as Python Shell and Script mode is known as Python Editor. It is a platform-independent language.  
We find it interesting to work with Python.  

Answer

Interactive Modes

>>> print("Python is easy to learn and write.")
>>> print("It allows us to work in two modes: Interactive mode and Script mode.")
>>> print("Interactive mode is also known as Python Shell and Script mode is known as Python Editor. It is a platform-independent language.")
>>> print("We find it interesting to work with Python.")

Script Modes

print("Python is easy to learn and write.")
print("It allows us to work in two modes: Interactive mode and Script mode.")
print("Interactive mode is also known as Python Shell and Script mode is known as Python Editor. It is a platform-independent language.")
print("We find it interesting to work with Python.")
Output
Python is easy to learn and write.
It allows us to work in two modes: Interactive mode and Script mode.
Interactive mode is also known as Python Shell and Script mode is known as Python Editor. It is a platform-independent language.
We find it interesting to work with Python.

Question 28

Write a code that prints your full name and your birthday as separate strings.

Answer

full_name = "Jeevika Sharma"
birthday = "January 17, 2000"

print("Full Name:", full_name)
print("Birthday:", birthday)
Output
Full Name: Jeevika Sharma
Birthday: January 17, 2000

Question 29

Record what happens when the following statements are executed:

(a) print (n=17)

(b) print (8 + 9)

(c) print (4.2, "hello", 6 - 2, "world", 15/2.0)

(d) print ("123abc", sep = '-')

(e) print ("XXX", end ='!')

Answer

(a) print(n=17) — It raises an error because the syntax print(n=17) is incorrect. In this context, n=17 is trying to use an argument name assignment within the print() function, which is not valid.

(b) print(8 + 9) — 17

(c) print(4.2, "hello", 6 - 2, "world", 15/2.0) — 4.2 hello 4 world 7.5

(d) print("123abc", sep = '-') — 123abc

(e) print("XXX", end ='!') — XXX!

Question 30

Use IDLE to calculate:

(a) 6+4*10

(b) (6+4) *10

Answer

(a) 46

(b) 100

Question 31

Try the following code on Python Shell and evaluate the output generated:

>>> print("Python is easy to learn and write.")
>>> print(3.14159*7)
>>> print('I am a class XI' + 'student')
>>> print('I', 'm')
>>> print("class XI student")
>>> print("I'm", 16, "years old")

Answer

Python is easy to learn and write.
21.99113
I am a class XIstudent
I m
class XI student
I'm 16 years old

Question 32

Draw a flow chart to count and display the even and odd numbers in a given list of integers.

Answer

The flow chart is given below:

Draw a flow chart to count and display the even and odd numbers in a given list of integers. Getting Started with Python, Computer Science with Python Preeti Arora Solutions CBSE Class 11.
PrevNext