python_IX
python_IX
Pyhton
Answer: (iv)
Answer: (ii)
Answer: (iii)
Answer: (iii)
5. Which of the following is the valid name for (an) identifier(s) in Python?
i. Test#4
ii. Rollno
iii. 9thClass
iv. else (1)
Answer: (ii)
Answer: (i)
Answer: (iii)
8. Which of the following is a data type that has two built in values True or False?
i. String
ii. Boolean
iii. Integer
iv. Float (1)
Answer: (ii)
Answer: (ii)
Answer: (iii)
12. Which of the following statements allow to repeat a task for a fixed number of times?
i. for statement
ii. if…else statement
iii. while statement
iv. continue statement (1)
Answer: (i)
13. If L1 = [‘O’, ‘R’, ‘A’, ‘N’, ‘G’, ‘E’], then what will be the output of the following statement?
print(L1)
i. ‘ORANGE’
ii. [‘O’, ‘R’, ‘A’, ‘N’, ‘G’, ‘E’]
iii. ‘O’, ‘R’, ‘A’, ‘N’, ‘G’, ‘E’
iv. None of these (1)
Answer: (ii)
Answer: (i)
15. If L1 = [‘O’, ‘R’, ‘A’, ‘N’, ‘G’, ‘E’], then which of the following will be the output of the
given statement? print(L1[::-1])
i. Prints the list as it is
ii. Prints the list in reverse order
iii. Prints the last element of the list
iv. Prints the first element of the list (1)
Answer: (ii)
16. Which of the following is a step-by-step process to identify and solve a problem?
i. Flowchart
ii. Algorithm
iii. Code
iv. All of these (1)
Answer: (ii)
Answer: (iv)
Answer: (i)
Answer: (i)
Answer: F
22. While loop repeats a set of instructions indefinite number of times. (1)
Answer: T
23. For loop is used to give conditions and executes only once. (1)
Answer: F
24. If condition is True then the block of statement written for True will be executed. (1)
Answer: T
25. The count( ) returns the index number of the value given in the function. (1)
Answer: F
Answer: F
Answer: F
28. CodeCombat is a free coding educational game available on the internet. (1)
Answer: T
Answer: T
30. It is optional to specify colon(:) after writing a condition with the if statement (1)
Answer: F
Answer: T
Answer: T
33. There are different ways of visiting each element of a list. (1)
Answer: T
Answer: T
35. In Python the process of repeating a set of instructions based on a condition is called
loop. (1)
Answer: T
Answer: F
37. Flowcharts are not difficult to make and takes less time. (1)
Answer: F
Answer: T
Answer: F
40. There are no specific tools for branching and looping in algorithms. (1)
Answer: T
Fill in the blanks.
41. Remainder operator and floor division are ………………………. operators. (1)
Answer: arithmetic
42. .………………………. and ………………………. are two different ways of writing comments. (1
)
Answer: Single-line/Multi-line
43. The ………………………. function is used to find the data type of the objects. (1)
Answer: type()
Answer: program
45. There are ………………………. ways to repeat a set of instructions in Python. (1)
Answer: two
Answer: heterogeneous
Answer: algorithm
49. .………………………. and ………………………. are important tools before we write an actual code
in a specific computer language. (1)
Answer: flowcharts
Answer: += , -=
52. .………………………. is a character encoding standard that uses numeric codes to represent
characters in upper and lower case, numbers, and punctuation symbols. (1)
Answer: ASCII
Answer: None
54. In ………………………. programming the program instructions are executed one after the
other in a sequence. (1)
Answer: Python
Answer: mutable
56. -------- are used to increase the readability of the code. (1)
Answer: Comments
Answer: program
58. In ………………………. flow statements are placed one after the other. (1)
Answer: sequentia
Answer: True/False
60. Algorithm is ………………………. approach to identify and solve a problem. (1)
Answer: step-by-step
Answer: Punctuators are special symbols used in Python to organise statements and
expressions. Most commonly used punctuators in Python are: • ‘ " # \ () {} [] @ , : . =
Answer: Understanding the problem. • Analysing the problem. • Developing the solution.
• Coding and implementation
Answer: Guido van Rossum designed Python and released in 1991. He wanted to give a unique
name to it. So, he named it after the famous BBC comedy TV show "Monty Python's Flying
Circus".
Answer: Python simplifies the process of developing a program. The code is more close to
human language and away from machine language.
Answer: The two different modes of working in Python are: • Interactive Mode • Script
Mode
Answer: A list is created by enclosing the values within square brackets. Each value/element is
separated by a comma and stored under a common name. These values can be of different
data types. The name follows the rules of naming conventions for identifiers.
Answer: The pop( ) function removes an element from the list based on the index number
specified in the function and returns the deleted value.
70. Can we write more than one algorithm for the same problem? Explain. (2)
Answer: Many different algorithms might be acceptable for each problem. Due to the
flexibility of the English language, the same algorithm can often be expressed in more than
one way. In addition, there is almost always more than one way to solve a problem.
Answer: A block is identified by using an indentation (minimum 1 space). Ensure that all
statements in one block are indented at the same level.
Answer: You will need to enclose it with a pair of Triple quotes, one at the start and second in
the end. Anything inside the enclosing Triple quotes will become part of one multiline string.
73. What are variables? Why are they important in any programming language? (2)
Answer: Sort() function sorts the list in ascending or descending order. This is done "in the
list itself" and works for the list with values of the same data types.
76. What will be the output of the following statement? print([1, 2, 6] < [1, 2, 5]) (2)
Answer: False
Answer: Single line comment starts with hash symbol # followed by the text to be written as a
comment that lasts till the end of the line. For example, • # assigning a value to a variable
• num1 = 10 • num2 = 20 • # calculating the average • (num1 + num2) / 2
78. How many types of data types are there in Python? (2)
Answer: There are four types of data types in Python. These are: • Numbers: integer, float,
complex • None • Sequence: string, lists, tuples • Boolean: true, false
Answer: Relational operators or comparison operators compare the values given on both the
side of the operators and returns the boolean value either True or False. Examples of
relational operators are: equal to (==) and not equal to (!=).
Answer: CodeCombat is a free coding educational game that teaches you to learn JavaScript or
Python coding in a fun way. It is available for all age groups to suit the needs of all levels of
coding and computer science learners.
Answer: In sequential flow the statements are placed one after the other and the flow of
execution occurs starting from line1, line2 and so on with a top to down approach. It is the
default type followed in any programming language. For example: Steps for calculating
percentage of any student • Input marks of English, Hindi and Math • Total the marks •
Calculate the percentage • Display the percentage
Answer:
Answer: When the condition is True then the statements indented just below the if statement
will be executed and if the condition is False then the statements indented just below the else
statement will be executed. Syntax is:
if (condition):
Statements for True
else:
Statements for False
Example:
age=input("enter your age ")
if (age>=18):
print("eligible for driving")
else:
print("Not eligible")
Answer: It is used to repeat a set of instructions as long as the condition is true. It means when
the number of iterations are not fixed/indefinite before we start with the execution of a loop.
It is therefore known as indefinite loop. Indentation of statements is must to specify the block
of statements to be repeated using while loop. This loop is also called an entry-controlled
loop as it checks for the condition in the beginning only. If the condition is true then the body
of the loop will be executed. If the condition is false then it will not be allowed to enter within
the loop and it stops. Syntax of the while loop is: while <condition> Statements
Where, while is a keyword. condition is a criterion to repeat the instructions.
The instructions repeat till the condition is True. As soon as the condition is False, the control
exits from the loop. Statements are always indented can be single or a block and are
repeated till the condition is True.
Answer: In negative indexing, the index number begins with -1 till -length and we refer the
elements from right to left. For example: book=['C', 'O', 'M', 'P', 'U', 'T', 'E', 'R'] So,
each letter gets an element number starting from -1 print(book[-2]) will give an output
['E'] print(book[-7]) will give an output ['O']
Answer: List is mutable so data can be easily modified by overwriting a new value to an
existing value in a given list by using an assignment operator (=). Syntax list[index] =
newvalue For example: l1 = [10, 20, 40, 50] l1[3] = 100 print(l1)
Answer: N/A
89. Explain the first two steps involved in Computer Problem Solving. (4)
Answer: a) To solve this problem of writing a program we follow some steps as given below:
b) Understanding the Problem: This is a very important and difficult step where we need to
understand the main objective of a problem. Give more time to this step as the better you
understand the problem, the easier it will be to solve it. c) Analyzing the
Problem: In this step, we analyse what kind of data can be given as an input, what formula or
tool to use to do the processing and in which format the output will be displayed.
Answer: a) There are three different types of control structures Sequential flow, Selection flow
and Repetition flow. Sequential Flow In sequential flow, the statements are placed one
after the other and the flow of execution occurs starting from line1, line2 and so on with a
top-down approach. It is the default flow followed in any programming language. For example,
steps for calculating percentage of any student are: b) Input marks of English
Hindi and Math c) Total the marks d) Calculate the percentage
e) Display the percentage 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, if we consider the
above example where we have a condition-award to be given if the percentage is more than
90 only. f) Input marks of English Hindi and Math g) Total the
marks h) Calculate the percentage i) Display the percentage If
percentage is more than 90 then Display "Award given" Otherwise Display "No
award" Repetition Flow Repetition flow is also known as a loop as it 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 follow the concept of
repetition. a. Repeat for 10 people • Input marks of English Hindi and Math • Total
the marks • Calculate the percentage • Display the percentage • If percentage is
more than 90 then Display "Award given" Otherwise Display "No award"
j) Go up again till number of repeats is less than or equal to 10
91. Explain the three different numeric data types available in Python. (4)
Answer: • Integer: Integers are whole numbers (+ve, -ve or 0) with no fractions or decimal
value. Its length is dependent on the available memory. For example, 10, 124, 4567,
7812568751. • Float: It is a real number with floating point representation. For example,
15.5 and 12.0. It can also be represented using the exponent notation E. For example, 1E5 is
100000. • Complex: It is made up of a real number and an imaginary number. For
example, 3+2i where 3 is a real number and 2i is an imaginary number.
Answer: There are three kind of errors which a programmer encounters in Python— syntax
error, logical error and runtime error. Syntax Error:Syntax means writing the code
following the rules of Python language. Syntax error is occurred when we violating the rules of
Python language. This is the most common type of an error made by a programmer. If
there is typing error, incorrect indentation, or incorrect arguments given in a function then
Python will not be able to interpret the instruction and will raise a syntax error. Logical
Error:This kind of error is difficult to find since the program will run correctly but the desired
output is not achieved. This happens if we give a wrong formula for the calculation to be done,
write wrong logic for the problem to be solved through the code. Runtime Error:Runtime
error occurs during the execution of a program like wrong input or output errors, undefined
object errors, division by zero errors. This type of error will halt the program execution
unexpectedly.
Answer: For loop: It is used to repeat a set of instructions for a fixed number of times. It means
the number of iterations are known/definite before we start with the execution of a loop.
Therefore, the for loop is also known as definite loop. Indentation of statements is must to
specify the block of statements to be repeated using the for loop. While loop: The while
loop is used to repeat a set of instructions as long as the condition is true. It means when the
number of iterations are not fixed/indefinite before we start with the execution of a loop. It
is therefore known as indefinite loop. Indentation of statements is must to specify the block
of statements to be repeated using while loop.
94. What is Iteration? Explain two different ways of using iteration in Python. (4)
Answer: with the execution of a loop. Therefore, the for loop is also known as definite loop.
Indentation of statements is must to specify the block of statements to be repeated using the
for loop. The while loop The while loop is used to repeat a set of instructions as long as
the condition is true. It means when the number of iterations are not fixed/indefinite before 1.
we start with the execution of a loop. It is therefore known as indefinite loop. Indentation of
statements is must to specify the block of statements to be repeated using while loop. In
Python, the process of repeating a set of instructions based on a condition is called loop. There
are two types of loops in Python— for loop and while loop. The for Loop The for loop
is used to repeat a set of instructions for a fixed number of times. It means the number of
iterations are known/definite before we start
Answer: The list has the following important features: • It is mutable data type. • It is an
ordered sequence of values. • Each element is separated by comma and enclosed in square
brackets [ ]. • Each value/element is accessed by an index number. The values can be
added, modified or deleted by the user throughout the program. It stores the values of
different data types.
Answer: There are two different functions used to remove elements in an existing list remove(
) and pop( ). The remove( ) Function:The remove( ) function removes the first occurrence
of the element with the specified value. It means only one value can be removed at a time
even if there are duplicate values in the list. If you wish to remove multiple values then this
function can be used within a loop where it repeats itself a specific number of times. The
pop( ) Function:The pop( ) function removes an element from the list based on the index
number specified in the function and returns the deleted value. In case no index number is
given then by default it removes the last element from the list. If we try to remove an index
number which does not exist then it gives an IndexError
Answer: The elements of a list can be accessed by using its index number starts with 0 (zero).
There are two different ways of using the index number: • Forward Indexing: The index
number begins with 0 till length-1 and we refer the elements from left to right. •
Negative/Backward Indexing: The index number begins with -1 till -length and we refer the
elements from right to left.
Answer: a.
A=int(input("Enter the 1st angle= "))
B=int(input("Enter the 2nd angle= "))
C=int(input("Enter the 3rd angle= "))
S=A+B+C
if S==180:
print("The angles form a triangle")
else:
print("The angles do not form a triangle")
b.
F = int(input("Enter the temperature in fahrenheit: "))
C = ((F / 5) * 5) - 32
print(F, "degree fahrenheit is equal to ", C, "celcius")
c.
s=float(input("Enter the time in seconds: "))
m=s/60
print("The time in minutes is: ", m)
d.
x = int(input("Enter the length: "))
y = int(input("Enter the breadth: "))
if(x==y):
print("It's a square")
else:
print("It's not a square")
e.
weekday = int(input("Enter weekday day number (1-7) : "))
if weekday == 1 :
print("\nMonday");
elif weekday == 2 :
print("\nTuesday")
elif(weekday == 3) :
print("\nWednesday")
elif(weekday == 4) :
print("\nThursday")
elif(weekday == 5) :
print("\nFriday")
elif(weekday == 6) :
print("\nSaturday")
elif (weekday == 7) :
print("\nSunday")
else :
print("\nPlease enter weekday number between 1-7.")
f.
Salary = int(input("Enter the salary of the employee: "))
Years-of-Service = int(input("Enter the number of service years: "))
Bonus = (Salary * 0.15)
Net-Salary = 0
if Years-of-Service > 5:
Net-Salary = Salary + Bonus
print(Net-Salary)
g.
Bill-Amount = int(input("Enter the billing amount: "))
Discount = Bill-Amount * 0.1
if Bill-Amount > 5000:
Net-Amount = Bill-Amount - Discount
print("The net billing amount is: ", Net-Amount)
else:
print("The net billing amount is: ", Bill-Amount)
h.
Y = int(input("Enter the year: "))
if (Y % 4) ==0:
if(Y % 400) == 0:
print("The year entered is a leap year")
else:
print("The year entered is not a leap year")
99. What is the use of clear() and count() function with respect to a list? (4)
Answer: The uses of clear() and count() function are: • clear(): This function removes all the
elements of the list in one go. It empties the list but the empty list still exists in Python which
can be used later to fill the values. For example: city=["Delhi", "Mumbai", "Kolkata",
"Chennai"]
city.clear()
print(city)
Output will be: [ ]
• count(): This function counts the number of occurrences of the specified value in the given
list. If the value doesn’t exist, then the function returns 0. For example: marks = [56, 67, 45,
78, 56, 78, 12]
marks.count(78)
Output will be: 2
marks.count(10)
Output will be: 0 # 10 does not exist in the list.
100. Write a program to calculate the perimeter and area of the shape as per the user’s
choice: (1x4)
a) 1. Square
2. Rectangle
3. Circle
102. Assertion (A): Python is the most popular language when it comes to developing web
and internet applications. Reason (R): Python has pre-built libraries and web frameworks
like Pyramid, Django, and Flask, which are used for backend web development projects.
Some standard libraries also support content design, database connectivity and many
Internet protocols like HTTP, SMTP, XML etc (3x1)