Task (Page 393)
1. The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
2. radius = float(input("Enter the radius of the circle: "))
area = 3.14159 * radius * radius
perimeter = 2 * 3.14159 * radius
print("Area of the circle:", area)
print("Perimeter (Circumference) of the circle:", perimeter)
Task (Page 407)
1. abcabc
2. abcabc
3. abcabcabcabcabcabc
Task (Page 409)
● Output: ['N', 'I', 'A', 'U']
● This starts from index -1 (which is 'N') to the end of the list.
Output: ['N']
● This prints from the start (0) up to index -1 (exclusive), so it excludes the last element 'N'.
Output: ['E', 'D', 'U', 'C', 'A', 'T', 'I', 'O']
Exercise
Unsolved Questions
SECTION A (Objective Type Questions)
uiz
A. 1. d 2. c 3. a 4. d 5. a
B. 1. algorithm 2. 10 3. Flowchart 4. Documentation
5. Guido van Rossum, [Link] 6. =, += 7. ASCII
8. None 9. sequential 10. condition 11. else 12. Traversal
13. Negative 14. Syntax 15. clear()
C. 1. True 2. False 3. True 4. True 5. True
6. False 7. True 8. True 9. True 10. False
Touchpad Artificial Intelligence (Ver.3.0)-IX (Answer Key) 67
D. 1. x = 10
a = input("enter number: ")
print("number entered is", a)
b = 10
a = int(a) + 5
a = a + 10
print(a)
2. y = int(input("Enter Y: "))
if y < 10:
print("smaller")
else:
print(y)
3. M = int(input("Enter M: "))
while M < 10:
if M == 5:
print("Middle Value")
else:
print(M)
M += 1
4. str = "book"
i = 0
while i <= 1:
print(str, sep="%")
i += 1
E. 1. C = 1
while C < 5:
print(C)
C += 2
print("Python")
2. sum = 0
for i in range(20, 10, -2):
sum += i
print(sum)
F. 1. Output:
1022*1024*1026*1028*
68 Touchpad Artificial Intelligence (Ver.3.0)-IX (Answer Key)
2. Output:
50
3. Output:
0*2*4*
SECTION B (Subjective Type Questions)
A. 1. The two coding programs available in CodeCombat are Python and JavaScript.
2. Flowcharts are more preferred because they are visual, easier to understand, and clearly
show the flow of the program using symbols.
3. Yes, we can write multiple algorithms for the same problem as there can be different ways
to solve a problem based on logic and approach.
4. Selection flow allows the program to choose between different paths based on a condition
using statements like if, if-else, or if…elif…else.
5. Multi-line strings in Python can be created using triple quotes, either ''' or """.
6. The print() function is used to display output on the screen.
Example:
print("Hello")
print(5 + 3)
print("Age is", 12)
7. Variables are names used to store data. They are important because they allow programs
to store, change, and reuse values during execution.
8. Normal division (/) gives the result with decimals, while floor division (//) gives the largest
whole number less than or equal to the result.
9. Sequential programming means the instructions in a program are executed one after another
in the order they are written.
Consideration 2: The need for transparency and accountability in the use of generative AI,
ensuring that users are aware when they are interacting with AI-generated content.
10. A nested if statement is an if statement placed inside another if statement to check multiple
conditions.
11. Step value helps control the number of loop repetitions and prevents the loop from running
infinitely.
12. A while loop is called an entry-controlled loop because the condition is checked before the
loop body is executed.
13. The sort() function is used to arrange the elements of a list in ascending or descending order.
14. Key features of Python include simple syntax, readability, large library support, and cross-
platform compatibility.
Applications include web development, AI, machine learning, automation, data science, and
game development.
Touchpad Artificial Intelligence (Ver.3.0)-IX (Answer Key) 69
15. The pop() function removes an element by index and returns it, while remove() deletes the
first matching value from the list.
16. False – Because the comparison goes element by element, and 6 is not less than 5.
B. 1.
Algorithm Flowchart
It is a step-by-step textual approach to It is a graphical representation of a
solve a problem. algorithm.
It can be written in natural language,
It uses standardised symbols and shapes.
pseudocode, or code.
Difficult to represent branching and Easily represents branching and looping
looping. through symbols.
2.
SYMBOL NAMES SYMBOLS PURPOSE
Oval Used to start and stop a flowchart.
Parallelogram Used to take input and display output.
Used to perform assignment,
Rectangle mathematical and processing
operations.
3. To solve this problem of writing a program, we follow some steps as given below:
i. Understanding the problem: This is a crucial step where we need to understand the
main objective of the problem. In this step, we should clearly define the problem, gather
all necessary requirements, understand constraints, and clarify goals. These actions are
essential to moving in the right direction and finding an effective solution.
ii. Analysing the problem: Break down the problem into smaller parts, identify inputs and
outputs, and explore existing solutions. Consider edge cases and unusual scenarios. This
comprehensive analysis sets a detailed plan for tackling the problem.
iii. Developing the solution: Design a detailed algorithm and choose appropriate tools and
technologies. It is always recommended to first write an algorithm and draw a flowchart
for solving a problem and then only write the program. This translates analysis into a
practical, actionable plan.
70 Touchpad Artificial Intelligence (Ver.3.0)-IX (Answer Key)
iv. Coding and implementation: This is the last step where every instruction of an algorithm
is converted into a computer understandable instruction by using the syntax and semantic
of a specific computer language.
4. Control structures are a set of instructions that control the flow of instructions in a program.
It is a programming tool that determines the order of execution of the statements in any
programming language. There are three different types of control structures: sequential flow,
selection flow, and repetition flow. Let us learn about these in detail.
Sequential Flow
In sequential flow, the statements are placed one after the other and the flow of execution
occurs starting from line 1, line 2 and so on with a top-down approach. It is the default flow
followed in any programming language. For example, the steps for calculating the percentage
of any student by taking as an input marks of English, Science, Maths are as follows:
Step 1 Start
Step 2 Input Eng, Science, Math
Step 3 Total = Eng+Science+Math
Step 4 Percentage = (Total / Maximum_Marks) * 100
Step 5 Display Percentage Step 6 Stop
Selection Flow Selection flow is also known as branching control as the flow of control
branches based on a condition. A condition evaluates to either TRUE or FALSE. In the case of
TRUE, the flow of control follows the set of instructions written for True. In case it is FALSE,
then it follows the other route. For example, consider the scenario where an award is given
only if the percentage is more than 90:
Step 1 Start
Step 2 Input Eng, Science, Math
Step 3 Total = Eng+Science+Math
Step 4 Percentage = (Total / Maximum_Marks) * 100
Step 5 Display Percentage
Step 6 If Percentage> 90 then
Display "Award given"
Step 7 else
Display "No award"
Step 8 Stop
Repetition Flow Repetition flow, also known as a loop, repeats a set of instructions a number
of times based on a condition. For example, if we wish to repeat the above steps of calculating
percentage for 10 students then we use the concept of repetition.
Step 1 Start
Touchpad Artificial Intelligence (Ver.3.0)-IX (Answer Key) 71
Step 2 count=1
Step 3 if count <=10 goto Step 4 else goto step 10
Step 4 Input Eng,Science, Math
Step 5 Total= Eng+Science+Math
Step 6 Percentage = (Total / Maximum_Marks) * 100
Step 7 Display Percentage
Step 8 count=count+1
Step 9 Goto Step 3
Step 10 Stop
5. Arithmetic operators are used to perform mathematical operations on variables and values.
Following arithmetic operators are provided by Python:
Name Symbol Purpose Example Output
2+4 6
Addition + Adds two values. 2.0 + 4 6.0
"hi" + "all" "hiall"
Subtracts second value 6–2 4
Subtraction –
form the first value. 6.0 – 2 4.0
2*3 6
Multiplication * Multiplies two values. 1.5 * 2 3.0
"Hi" * 3 'HiHiHi'
4/2 2.0
Divides the first number 6.0 / 2 3.0
Division /
with the second number. 6 / 2.0 3.0
11 / 2 5.5
Remainder or Returns the remainder of 5%2 1
%
Modulus a division. 16 % 11 5
Second number raised
5 ** 2 25
Exponential ** to the power of the first
1.5 ** 2 2.25
number.
72 Touchpad Artificial Intelligence (Ver.3.0)-IX (Answer Key)