IntroPython
IntroPython
Answer: (iv)
Answer: (ii)
3. Which of the following symbols is used to display the decision-making statements in a flowchart?
i. Rectangle
ii. Line
iii. Diamond
iv. Oval (1)
Answer: (iii)
4. Which of the following is the step-by-step approach in simple English like statements?
i. Algorithm
ii. Selection
iii. Flowchart
iv. Sequence (1)
Answer: (i)
Answer: (iii)
6. Which of the following is the valid name for (an) identifier(s) in Python?
© Orange - Touchpad 1
i. Test#4
ii. Rollno
iii. 9thClass
iv. else (1)
Answer: (ii)
Answer: (i)
Answer: (iii)
Answer: (iii)
10. 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)
11. Which of the following conditional statements is used to test multiple conditions?
i. if
ii. if…elif…else
iii. if…else
iv. All of these (1)
Answer: (ii)
12. What will be the output of the following code? if(True): print(“Hello”) else: print(“Hi”)
© Orange - Touchpad 2
i. Hello
ii. Hello Hi
iii. Hi
iv. Nothing will print (1)
Answer: (i)
Answer: (iv)
Answer: (iii)
15. 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)
Answer: (iv)
17. If a list named L1 contains 4 elements, then which of the following can be used to access the last
element of the L1 list?
i. L1[4-1]
ii. L1[4]
iii. L1[-1]
iv. Both a and c (1)
Answer: (iv)
© Orange - Touchpad 3
18. 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)
19. Consider the following code:A = [“Orange”] B = [“Education”] C=A+B print(C) Which of
the following will be the output of the preceding code?
i. [‘Orange’, ‘Education’]
ii. [‘Orange Education’]
iii. Orange Education
iv. Orange + Education (1)
Answer: (i)
20. 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)
21. 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)
© Orange - Touchpad 4
Answer: (i)
Answer: (i)
Answer: (iii)
26. Which of the following control structures is also known as branching control?
i. Sequential flow
ii. Selection flow
iii. Repetition flow
iv. None of these (1)
Answer: (ii)
Answer: (iv)
Answer: F
Answer: F
30. Flow charts are difficult to maintain for complex programs. (1)
Answer: T
© Orange - Touchpad 5
31. There are no specific tools for branching and looping in algorithms. (1)
Answer: T
32. Algorithms are just a waste of time before writing a code. (1)
Answer: F
Answer: T
Answer: F
35. While loop repeats a set of instructions indefinite number of times. (1)
Answer: T
36. For loop is used to give conditions and executes only once. (1)
Answer: F
37. If condition is True then the block of statement written for True will be executed. (1)
Answer: T
38. The count( ) returns the index number of the value given in the function. (1)
Answer: F
Answer: T
Answer: F
Answer: T
Answer: T
© Orange - Touchpad 6
43. Modification of the program through flowchart is sometimes time-consuming. (1)
Answer: T
Answer: F
45. CodeCombat is a free coding educational game available on the internet. (1)
Answer: T
Answer: T
Answer: T
48. It is optional to specify colon(:) after writing a condition with the if statement (1)
Answer: F
Answer: T
Answer: T
51. There are different ways of visiting each element of a list. (1)
Answer: T
52. The append() can be used to append any value at any location in a list. (1)
Answer: F
Answer: T
Answer: T
© Orange - Touchpad 7
Answer: T
56. In Python the process of repeating a set of instructions based on a condition is called loop. (1)
Answer: T
Answer: F
58. Flowcharts are not difficult to make and takes less time. (1)
Answer: F
Answer: T
Answer: interpreter
61. Remainder operator and floor division are ………………………. operators. (1)
Answer: arithmetic
62. .………………………. and ………………………. are two different ways of writing comments. (1)
Answer: Single-line/Multi-line
63. The ………………………. function is used to find the data type of the objects. (1)
Answer: type()
Answer: program
65. Conditional programming allows a block of statement to be executed based on a …………………. . (1)
Answer: condition
66. There are ………………………. ways to repeat a set of instructions in Python. (1)
Answer: two
© Orange - Touchpad 8
67. While loop is also called ………………………. loop. (1)
Answer: heterogeneous
Answer: mutable
70. The index number begins with 0 till length-1in ………………………. . (1)
Answer: algorithm
72. .………………………. and ………………………. are important tools before we write an actual code in a specific
computer language. (1)
Answer: flowcharts
Answer: Flowchart
75. .………………………. designed Python and released it in 1991 can be freely downloaded from the website
………………………. . (1)
Answer: += , -=
77. .………………………. is a character encoding standard that uses numeric codes to represent characters in
upper and lower case, numbers, and punctuation symbols. (1)
Answer: ASCII
© Orange - Touchpad 9
Answer: None
79. In ………………………. programming the program instructions are executed one after the other in a
sequence. (1)
Answer: Python
80. The block of statements is executed based on a ………………………. using if statement. (1)
Answer: condition
Answer: else
82. .………………………. means visiting each element and processing it as required by a program. (1)
Answer: Traversing
Answer: List
Answer: mutable
85. ………………………. function will delete all the elements in a list. (1)
Answer: clear()
86. ----------------- are those operators which take the value of the operand on the right side, perform an
operation and assign the result to the operand on the left side. (1)
87. -------- are used to increase the readability of the code. (1)
Answer: Comments
Answer: program
89. In ………………………. flow statements are placed one after the other. (1)
Answer: sequentia
© Orange - Touchpad 10
90. In branching statement, condition evaluates to either ………………………. or ………………………. . (1)
Answer: True/False
Answer: step-by-step
Answer: a) c b) a c) b d) e e) d
93. (1)
Answer: Punctuators are special symbols used in Python to organise statements and expressions. Most
commonly used punctuators in Python are: ‘ " # \ () {} [] @ , : . =
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: An algorithm is a step-by-step approach to identify and solve a problem in a finite time. It is used in a
problem-solving phase of any programming task and helps in defining the clear instructions in sequence. An
© Orange - Touchpad 11
algorithm uses simple English like statements to represent the steps of a program.
Answer: Logical operators are used to combine one or more conditional statements and returns either True or
False based on the evaluation of the conditions. Examples of logical operators are AND, OR, NOT.
Answer: Understanding the problem. • Analysing the problem. • Developing the solution. • Coding and
implementation
99. What is the difference between pop( ) and remove( ) functions? (1)
Answer: The remove( ) function removes the first occurrence of the element with the specified value. The
pop( ) function removes an element from the list based on the index number specified in the function and
returns the deleted value.
Answer: The step-by-step instruction written in any programming language to do a specific task is known as a
Program. A program is written in any programming language which the computer can understand and
execute.
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.
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 (4x1)
103. Assertion (A): Creating an algorithm before writing a program helps us. Reason (R): Algorithm is a
step-by-step representation of a solution to a given problem and uses simple English like statements so it is
easy to understand and write. The problem is broken down into smaller pieces hence it is easy to convert it
into a program using any programming language. (4x1)
a) Both Assertion (A) and Reason (R) are correct, but Reason (R) is not the correct
© Orange - Touchpad 12
explanation of Assertion (A).
b) Assertion (A) is not correct, but Reason (R) is correct.
c) Assertion (A) is correct, but Reason (R) is not correct.
d) Both Assertion (A) and Reason (R) are correct and Reason (R) is the correct explanation of
Assertion (A).
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: Tokens are the smallest meaningful unit of a program. Tokens supported by Python are Keywords,
Identifiers, Literals, Operators and Punctuators.
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: Sometimes we have a situation where we need to repeat a set of instructions a number of times then
we put it in a loop which repeats automatically. This is called Iteration.
Answer: The + operator is used to concatenate the list with another list.
Answer: Traversing a list means to visit each element and process it as required by a program.
© Orange - Touchpad 13
113. What is the use of the pop( ) function? (1)
Answer: The pop( ) function removes an element from the list based on the index number specified in the
function and returns the deleted value.
Answer: • CodeCombat: It is the company's original coding game recommended for parents, individuals,
educators and students. • Ozaria: It is an adventure game, fantasy story, and Computer Science program
recommended for educators and students.
Answer: Flowcharts are easier to understand than algorithms as they are represented in pictorial forms. One
can easily write the code by looking at the flowchart.
116. Can we write more than one algorithm for the same problem? Explain. (1)
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: The selection control structure allows one set of statements to be executed if a condition is true and
another set of actions to be executed if a condition is false.
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.
120. What are variables? Why are they important in any programming language? (1)
Answer: Variables are used to store information to be referenced and manipulated in a computer program.
They also provide a way of labeling data with a descriptive name, so our programs can be understood more
clearly by the reader and ourselves
Answer: Floor division divides the first number with the second number and returns the whole number
adjusted left to the number line whereas normal division just divides the two values.
© Orange - Touchpad 14
Answer: A sequential programming is when the algorithm to be solved consists of operations one after the
other, where there are no sentences that are repeated or you do not have to do alternative operations. For
example: The alarm sounds. You wake up. You brush your teeth.
Answer: A nested if statement is an if statement placed inside another if statement. Nested if statements are
often used when you must test a combination of conditions before deciding on the proper action.
Answer: Step value is the value by which the counter variable is incremented or decremented every time the
loop body is executed. It can be a positive or a negative value, but it cannot be zero. The step value is optional.
In case it is omitted, the counter variable is increased by one every time the loop is executed.
Answer: While loop is 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.
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.
127. What is a use of print( ) function? Give a few examples to support your answer. (1)
Answer: The print() function prints the specified message to the screen, or other standard output device.
128. What will be the output of the following statement? print([1, 2, 6] < [1, 2, 5]) (1)
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
Answer: Words that have special meaning are reserved by Python for special purposes and are not allowed to
be used as identifiers. Break, key, import, return, while, etc. are few examples of keywords.
131. How many types of data types are there in Python? (1)
Answer: There are four types of data types in Python. These are: • Numbers: integer, float, complex •
None • Sequence: string, lists, tuples • Boolean: true, false
© Orange - Touchpad 15
132. What are relational operators? (1)
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:
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: • Oval Used to start and end a flowchart. • Parallelogram Used for input and output operation.
• Rectangle Used for assignment, mathematical operations, processing • Diamond Used for decision
making in case of branching or looping. • Arrow Used for to show the direction of flow of
information.
136. Explain the use of print( ) function with all its parameters. (1)
Answer: The print() function is used to print an output on the screen. It converts the expressions into a string
before writing to the screen. Syntax to use the print( ) function is: print(object(s), sep = separator,
end = end) Where, • object can be one or more separated by comma and it can be a variable, literal,
expression. An object will be converted to string before printed. • sep is used as a separator if there are
© Orange - Touchpad 16
more than one objects. • end specifies what to print at the end. Default is#
#‘\n’
Answer: • Simple statements: By default, the end of a statement is done by pressing an Enter key. Each
statement is written on a new line. a=5 is a simple statement where variable-a is created with value 5.
c=a + b • Multiline Statements: We can make a statement that extends over multiple lines by using line
continuation character (\) as shown below: a = 4 + 5 +\ 6 + 7 +\ 8+9 The main advantage of
using multiline is when we need to do long calculations and cannot fit these statements into one line.
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 for a fixed number of times. It means when the number of
iterations are known/definite before we start with the execution of a loop. It is therefore also known as
definite loop. Indentation of statements is must to specify the block of statements to be repeated using for
loop. There are two ways suing for loop: • Using sequence • Using range() function Example:
for i in range(10, 0, -1): print(i)
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.
© Orange - Touchpad 17
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
Answer: N/A
© Orange - Touchpad 18
Answer:
146. Explain the first two steps involved in Computer Problem Solving. (1)
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
© Orange - Touchpad 19
Answer:
149. Explain the three different numeric data types available in Python. (1)
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: The three programming constructs are: Sequential Statements:A step-by-step process of
execution of code is called sequential flow of control. This is the default flow of execution of a program. It
means that the computer will run the code one line at a time starting from line 1, followed by line 2 and so on
till it reaches the last line of the program. Selection Statements: In Python, Selection flow of control is
© Orange - Touchpad 20
achieved through conditional statements. In the conditional/selection statements, flow of control is changed
based on a condition. We specify the condition in the program which evaluates to either True or False. If
condition is True then the block of statement written for True will be executed and in case the condition is
False then the block of statements for False will be executed. Iterative Statements: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
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.
153. List the important rules to remember when using range() function in for loop. (1)
Answer: Using the range() Function: The range( ) function is an inbuilt function that is used to generate a set of
values between the specified range. for <Var> in range(<Start>, <End+1>, <Step>): Statements
Where, for, in and range are keywords. Start, End and Step are parameters of range() function and will
always be integers. Start is a starting value of loop and End is an ending value+1 of loop, Step is the number
of steps taken to reach the end value. If only two parameters are used then Step value becomes 1 by
default. If only one parameter is used the Start becomes 0 and Step becomes 1 by default. If Start > End
then Step is a -ve integer should be given. If Start < End then Step is a +ve integer. If Start >= End and
Step value is not specified then it assumes as +ve which is an invalid condition to run a loop so the loop will
not execute at all.
154. What is Iteration? Explain two different ways of using iteration in Python. (1)
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: 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 * operator is used to replicate a list specific number of times. With * operator, one operand has
to be a list and the other should only be an integer, otherwise it will give an error.
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) s=float(input("Enter the time in seconds: ")) m=s/60 print("The time in minutes is: ", m)
© Orange - Touchpad 22
d. Input length and breadth and display whether it is a square or not. Ans. 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") b) 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") c) 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) d) 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) e) F = int(input("Enter
the temperature in fahrenheit: ")) C = ((F / 5) * 5) - 32 print(F, "degree fahrenheit is equal to ", C,
"celcius") f) 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") g) 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.")
160. What is the use of clear() and count() function with respect to a list? (1x1)
a) 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.
Answer: N/A
161. Write a program to calculate the perimeter and area of the shape as per the user’s choice: (3x1)
a) Square
b) Rectangle
c) Circle
Answer: a) Program: c = int(input("Enter your choice: ")) if c==1: a = float(input("Enter the side of
the square: ")) print("The perimeter of the square is: ", a*4) print("The area of the square is: ",
a*a) elif c==2: l = float(input("Enter the length of the rectangle: ")) b = float(input("Enter the
breadth of the rectangle: ")) print("The perimeter of the rectangle is: ", 2*(l+b)) print("The area
of the rectangle is: ", l*b) elif c==3: r = float("Enter the radius of the circle: ") print("The
circumfrence of the circle is: ", 2*3.14*r) print("The area of the circle is: ", 3.14*r*r) else:
print("Invalid choice") b) N/A c) N/A
© Orange - Touchpad 23
© Orange - Touchpad 24