Chapter 3
Chapter 3
1. Python is free and open-source programming language. It means that anyone can download, use,
modifyand distribute it without any licensing fees or legal restrictions. In addition, Python’s source
code isavailable for anyone to access, modify and distribute as per their requirements.
2. Limitations of Python:
(a) Speed: Python is an interpreted language, which means that it is generally slower compared to
(b) Mobile Development: Python is not a very good language for mobile development. It is seen as a
(c) Memory Consumption: Python is not a good choice for memory-intensive tasks. Due to the
flexibility of the data types, Python’s memory consumption is also high.
(d) Runtime Errors: Python programmers have cited several issues with the design of the language.
Because the language is dynamically typed, it requires more testing and has errors that only show
up at run-time.
(a) In script mode, Python code is executed from a script file with a “.py” extension. The code is saved
in a file and the entire script is executed sequentially from start to finish. On the other hand,
interactive mode allows you to execute Python statements and expressions directly in an interactive
(b) In script mode, the input to the program is usually provided through predefined variables,
command-line arguments or reading from files. The output is typically written to the console or
saved to files. In interactive mode, you can interactively enter input at the prompt and immediately
see the output. Each line of code is executed and evaluated as soon as you press the Enter key.
(c) Script mode is commonly used for developing larger projects or reusable code that can be run
repeatedly. On the other hand, interactive mode is useful for experimenting, testing snippets of
4. A flowchart and an algorithm are both tools used in computer programming, but they are different
in nature and serve different purposes. Here are the differences between flowchart and algorithm:
(a) A flowchart is a graphical representation of a process, using symbols, shapes and arrows to
illustrate the flow of information or steps involved in solving a problem. An algorithm, on the other
hand, is a step-by-step procedure for solving a problem or performing a task, which can be
implemented in code.
(b) A flowchart is a visual representation of a process, while an algorithm is a set of instructions that
(c) A flowchart provides a high-level view of a process, showing the steps involved in solving a
problem or performing a task. An algorithm provides a detailed step-by-step description of how to
perform each step.
(d) A flowchart is represented using symbols, while an algorithm is represented using a natural
5. The pseudocode to read two numbers, divide one by another and display the quotient:
(a) Start
(h) End
(a) Start
(i) Read the result of the coin flip (1 for player 1 win, 2 for player 2 win).
(g) End
7. A pseudocode to print all multiples of 5 between 10 and 25 (including both 10 and 25):
(a) Start
(d) End
(a) Start
Read marks for Computer Science from the user and store them in the cs
Read marks for Mathematics from the user and store them in the math
Read marks for Physics from the user and store them in phys
End
9. The algorithm to find the greatest among two different numbers entered by the user:
(a) Start
(b) Declare variables num1 and num2 to store the two input numbers
(f) Otherwise, if num2 is greater than num1, display “num2 is the greatest”
(g) Otherwise, if num1 and num2 are equal, display “Both numbers are equal”
(h) End
(a) Start
(c) Read the number from the user and store it in num
(h) End
11. Algorithm to accept four numbers as input and find the largest and smallest of them:
(a) Start
(b) Declare variables num1, num2, num3, num4, largest and smallest
(l) If num2 is less than the smallest, set the smallest equal to num2
(m) If num3 is less than the smallest, set the smallest equal to num3
(n) If num4 is less than the smallest, set the smallest equal to num4
(p) End
12. The concept of decomposition is based on breaking down complex systems or problems into
smaller, more manageable components. By doing so, we can understand each component in isolation
and tackle each one individually, leading to a simpler and more manageable solution overall.
(a) Start
• Multiply factorial by i
• Increment i by 1
15. Pseudocode to print the bill depending upon the price and quantity of an item:
(a) Start
(c) Read the price of the item from the user and store it in the price variable
(d) Read the quantity of the item from the user and store it in the quantity variable
(e) Multiply the price by the quantity to calculate the total cost and store it in the total cost variable
(g) Calculate the GST by multiplying the total cost by 0.05 (5%) and store it in the GST variable
(h) Add the GST to the total cost to calculate the bill GST, and store it in a variable with the same
name
(j) End
16. Python was first released on February 20, 1991, by its creator, Guido van Rossum. The initial
release was Python 0.9.0, which was a successor to the ABC language.
17. Python was developed by Guido van Rossum, a Dutch programmer, in the late 1980s and early
1990s. The design of Python was influenced by two programming languages: ABC and Modula-3. ABC
was a language designed for teaching programming concepts and it had an easy-to-learn syntax and
interactive shell. Modula-3, on the other hand, was a system programming language that had a
strong module system and support for low-level programming.
18. Yes, Python is a case-sensitive programming language, which means that it distinguishes between
uppercase and lowercase letters. For example, the variable name and Name are two different
variables in Python.
19. IDLE is a simple Integrated Development 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.
20. In Python, both displaying and printing are methods of outputting data to the console or
terminal, but there is a difference between them. Displaying: means showing data or output on the
console, but without actually printing it. In Python, this is often done by calling a function that
returns a value, such as assigning a value to a variable. For example, consider the following code:
x=5
x*2
In this code, the expression x * 2 is evaluated and its result, 10, is computed. However, this value is
not printed or displayed on the console.
Printing: on the other hand, means outputting data to the console so that it is visible to the user. In
Python, this is done using the print() function. For example:
x=5
print(x * 2)
In this code, the value of x * 2, which is 10, is printed to the console using the print() function.
(a) Simple and Easy: Python is a simple language that is easy to learn.
(b) Free/Open Source: Anybody can use Python without the need to purchase a license.
(c) High-level Language: Being a high-level language, it can be easily understood by the user without
the need to be concerned with low-level details.
(e) Extensible and Embeddable: Python programs support the usage of C/C++ codes.
(f) Standard Library: Python standard library contains pre-written tools for programming.
22. Cross-platform software is software that can run on multiple operating systems or platforms
without requiring modification. In the context of Python, it means that Python programs can be
written once and run on multiple platforms, such as Windows, Linux, and macOS, without making
any changes to the code.
(a) Platform-independent: It is platform-independent and can run across different operating systems/
platforms like Windows, Linux/Unix, macOS and other operating systems.
(b) Readability: Python programs use clear, simple, concise and English-like instructions that are easy
to read and understand even by non-programmers or people with no substantial programming
background.
(d) Higher Productivity: Since Python is a simple language with small codes and extensive libraries, it
offers higher productivity to programmers than languages like C++ and Java.
(e) Syntax Highlighting: It allows distinguishing between input, output and error messages by
different color codes.
(a) Interactive Mode: In this mode, we can execute Python code interactively, line by line and see the
results immediately. We can run Python in interactive mode by opening a Python interpreter, which
allows us to enter Python commands and see their output immediately. Interactive mode is useful
for testing and experimenting with small code snippets.
(b) Script Mode: In this mode, we can write a Python program in a script file, save it and then
execute it using the Python interpreter. We can create a Python script using a text editor or an
integrated development environment (IDE) such as IDLE. Script mode is useful for writing larger
programs or scripts that need to be executed multiple times.
(a) We can get immediate feedback for each line of code you enter, which allows for quick
experimentation and testing.
(b) It is easy to debug code in interactive mode, as you can quickly test different inputs and see the
results.
(a) Interactive mode is best suited for small to medium-sized projects and it can be tedious for larger
projects.
(b) Code written in interactive mode is not easily reusable in other projects or scripts.
(b) Type the following commands and press enter after each line:
(ii) print("It allows us to work in two modes: Interactive mode and Script mode.")
(iii) print("Interactive mode is also known as Python Shell and Script mode is known as Python Editor.
It is a platform-independent language.")
(d) Type “python filename.py” and press enter, where the filename
(b) Type the following code and save the file with a .py extension:
(ii) print("It allows us to work in two modes: Interactive mode and Script mode.")
(iii) print("Interactive mode is also known as Python Shell and Script mode is known as Python Editor.
It is a platform-independent language.")
(c) Type “python filename.py” and press enter, where the filename is the name of the file we saved
in step 2.
28. Do it yourself
(c) print(4.2, "hello", 6-2, "world", 15/2.0) – the output will be 4.2 hello 4 7.5
30. (a) 46
(b) 100
31. Output:
• 21.99113
• I am a class XI student
• I’m
• class XI student