0% found this document useful (0 votes)
4 views

IntroPython

The document is a comprehensive introduction to Python, featuring multiple-choice questions, true/false statements, fill-in-the-blanks, matching questions, and short answer questions that cover various programming concepts. Key topics include flowcharts, algorithms, data types, control structures, and Python syntax. Additionally, it highlights the importance of logical operators, lists, and the use of tools like CodeCombat for learning programming.

Uploaded by

dragonprince901
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

IntroPython

The document is a comprehensive introduction to Python, featuring multiple-choice questions, true/false statements, fill-in-the-blanks, matching questions, and short answer questions that cover various programming concepts. Key topics include flowcharts, algorithms, data types, control structures, and Python syntax. Additionally, it highlights the importance of logical operators, lists, and the use of tools like CodeCombat for learning programming.

Uploaded by

dragonprince901
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Introduction to Python

Multiple Choice Question


1. Which of the following symbols is used in flowcharts to take an input from the user?
i. Diamond
ii. Rectangle
iii. Oval
iv. Parallelogram (1)

Answer: (iv)

2. Coding and implementation is the ………………………. step in problem solving.


i. First
ii. Last
iii. Third
iv. Second (1)

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)

5. Which of the following is/are powerful tools for learning programming?


i. Flowchart
ii. Algorithm
iii. Both a and b
iv. None of these (1)

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)

7. Which of the following is a valid logical operator?


i. and
ii. !=
iii. +
iv. >= (1)

Answer: (i)

8. ZeroDivisionError error is a ………………………. .


i. Syntax Error
ii. Logical Erro
iii. Runtime Error
iv. Not an Error (1)

Answer: (iii)

9. Which of the following is a sequence of UNICODE characters?


i. Boolean
ii. Numbers
iii. String
iv. Float (1)

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)

13. Which of the following is not the conditional statement in Python?


i. if Statement
ii. if...elif...else Statement
iii. if…else Statement
iv. None of these (1)

Answer: (iv)

14. Which of the following is a looping statement in Python?


i. for statement
ii. while statement
iii. Both a and b
iv. None of these (1)

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)

16. Which of the following can be a part of a list?


i. String values
ii. Integer values
iii. List
iv. All of these (1)

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)

22. Which of the following is not an advantage of Python?


i. Cross platform language
ii. Easy to learn and use
iii. Supports GUI
iv. None of these (1)

Answer: (iv)

23. Which data type is used to store numbers?


i. Integer
ii. Sequence
iii. Sets
iv. None of these (1)

© Orange - Touchpad 4
Answer: (i)

24. Which of the following is not a valid identifier?


i. -Class8th
ii. Myclass
iii. Class9
iv. Work123 (1)

Answer: (i)

25. Which of the following is not a mathematical operator?


i. +
ii. –
iii. #
iv. = = (1)

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)

27. Which of the following is not an advantage of a flowchart?


i. It is an effective way to solve and analyze a problem.
ii. The flowchart makes program or system maintenance easier.
iii. It is used in preparing documentation of an application or a process.
iv. It is a time-consuming process. (1)

Answer: (iv)

Write True or False.


28. Understanding the problem is the last step in computer problem solving. (1)

Answer: F

29. Algorithm follows strict rules of writing the instructions. (1)

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

33. Step value is compulsory in while loop. (1)

Answer: T

34. Indentation is not important in conditional programming. (1)

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

39. Slicing a list means accessing a specific portion of a list. (1)

Answer: T

40. Operands on either side of the + operator have to be a list. (1)

Answer: F

41. We cannot create an empty list. (1)

Answer: T

42. A list can be created within another list. (1)

Answer: T

© Orange - Touchpad 6
43. Modification of the program through flowchart is sometimes time-consuming. (1)

Answer: T

44. It is easy to represent branching and looping in an algorithm. (1)

Answer: F

45. CodeCombat is a free coding educational game available on the internet. (1)

Answer: T

46. Integers are used for mathematical calculations. (1)

Answer: T

47. Python is easy to learn high level programming language. (1)

Answer: T

48. It is optional to specify colon(:) after writing a condition with the if statement (1)

Answer: F

49. Step value can be -ve or +ve in for loop. (1)

Answer: T

50. Each value/element is separated by a comma. (1)

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

53. Null is not a data type. (1)

Answer: T

54. NOT is not a relational operator. (1)

Answer: T

55. Conditional programming is done using if statement. (1)

© 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

57. In Python, lists are not mutable. (1)

Answer: F

58. Flowcharts are not difficult to make and takes less time. (1)

Answer: F

59. == and != are examples of relational operators. (1)

Answer: T

Fill in the blanks.


60. Python is an ………………………. language. (1)

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()

64. A ………………………. is a set of instructions given to a computer to do a specific task. (1)

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: entry-controlled loop

68. List is a collection of ………………………. data arranged in a sequence. (1)

Answer: heterogeneous

69. List is a ………………………. data type in python. (1)

Answer: mutable

70. The index number begins with 0 till length-1in ………………………. . (1)

Answer: Forward Indexing

71. An ………………………. uses simple English like statements. (1)

Answer: algorithm

72. .………………………. and ………………………. are important tools before we write an actual code in a specific
computer language. (1)

Answer: algorithm, flowchart

73. .………………………. uses symbols for writing a set of instructions. (1)

Answer: flowcharts

74. .………………………. is used for preparing documentation of an application. (1)

Answer: Flowchart

75. .………………………. designed Python and released it in 1991 can be freely downloaded from the website
………………………. . (1)

Answer: Guido van Rossum,

76. Examples of assignment operators are ………………………. and ………………………. . (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

78. .………………………. is a special literal. (1)

© 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

81. .………………………. keyword is optional with if statement. (1)

Answer: else

82. .………………………. means visiting each element and processing it as required by a program. (1)

Answer: Traversing

83. .………………………. indexing begins with -1. (1)

Answer: List

84. The elements in a list can be of ………………………. data types. (1)

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)

Answer: Augmented assignment operators

87. -------- are used to increase the readability of the code. (1)

Answer: Comments

88. A ………………………. is written in any programming language. (1)

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

91. Algorithm is ………………………. approach to identify and solve a problem. (1)

Answer: step-by-step

Match the following.


92. (1)

Answer: a) c b) a c) b d) e e) d

93. (1)

Answer: a) (iv) b) (v) c) (i) d) (ii) e) (iii)

Short answer type questions.


94. What are punctuators in Python? (1)

Answer: Punctuators are special symbols used in Python to organise statements and expressions. Most
commonly used punctuators in Python are: ‘ " # \ () {} [] @ , : . =

95. How do you create a list in Python? (1)

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.

96. Write a short note on algorithm. (1)

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.

97. Write a short note on logical operators. (1)

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.

98. Name the steps involved in Computer Problem solving. (1)

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.

100. What is a Program? (1)

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.

101. What is CodeCombat? (1)

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)

a) Both A and R are correct but R is NOT the correct explanation of A.


b) Both A and R are correct and R is the correct explanation of A.
c) A is correct but R is not correct.
d) A is not correct but R is correct

Answer: a) N/A b) a c) N/A d) N/A

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: a) N/A b) N/A c) N/A d) a

104. How did Python get its name? (1)

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".

105. Why is Python considered as a high-level language? (1)

Answer: Python simplifies the process of developing a program. The code is more close to human language
and away from machine language.

106. Name different modes of working in Python. (1)

Answer: The two different modes of working in Python are: • Interactive Mode • Script Mode

107. What are tokens in Python? Name a few of them. (1)

Answer: Tokens are the smallest meaningful unit of a program. Tokens supported by Python are Keywords,
Identifiers, Literals, Operators and Punctuators.

108. What is the use of if statement in Python? (1)

Answer: It executes the set of statements based on a condition.

109. How is a block of statements identified in Selection or Iteration? (1)

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.

110. What is iteration? (1)

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.

111. What is the use of the + operator with lists? (1)

Answer: The + operator is used to concatenate the list with another list.

112. What do you mean by traversing a list? (1)

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.

114. Name the two coding programs available in CodeCombat (1)

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.

115. Why are flowcharts more preferred than algorithms? (1)

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.

117. What is the meaning of selection flow in control structures? (1)

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.

118. How can we create a multi-line string in Python? (1)

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.

119. What is the use of an arrow in flowchart? (1)

Answer: It controls the direction of flow of instructions in a flowchart.

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

121. How is floor division different from normal division? (1)

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.

122. What is the meaning of Sequential Programming? (1)

© 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.

123. What is nested if statement? (1)

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.

124. Why is it necessary to give step value in while loop? (1)

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.

125. Why while loop is called entry controlled loop? (1)

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.

126. What is the use of sort( ) function of a list? (1)

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

129. What is a single line comment? (1)

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

130. What are keywords? (1)

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 (!=).

133. What is order of precedence in Python? (1)

Answer:

Longans answer type questions.


134. What is sequential flow? Explain with an example. (1)

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

135. Explain the important symbols of flowchart. (1)

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’

137. Give two different ways of writing statements in Python. (1)

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.

138. Explain if…else statement with example. (1)

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")

139. Explain for loop with an example. (1)

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)

140. Explain while loop with example. (1)

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.

141. What is negative indexing? Explain with an example. (1)

© 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']

142. How can we modify elements in a list? (1)

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)

143. Find the output of the following codes: (1)

Answer: N/A

144. Give three differences between an algorithm and a flowchart. (1)

Answer: N/A

145. Explain three symbols used in flowcharts. (1)

© 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.

147. Explain with example the three control structures. (1)

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

148. Explain mathematical operators with examples. (1)

© 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.

150. Explain three different types of errors in Python. (1)

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.

151. Define all the three important programming constructs. (1)

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

152. Differentiate between for loop and while loop. (1)

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

155. What are important features of lists in Python? (1)


© Orange - Touchpad 21
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.

156. Name different ways of deleting an element in a list. (1)

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

157. What is the use of * operator in a list. (1)

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.

158. Explain two different ways of indexing in a list. (1)

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.

159. Write Python code for the given instructions. (7x1)

a) Input time in seconds and change it into minutes.


b) Input a year and check whether it is a leap year or not
c) Input Salary and Years of Service. If the number of years are more than 5 then give an extra bonus of
15%. Display the net salary after adding the bonus.
d) Input a billing amount of shopping done. If the amount is more than 5000 then give a discount of
10%.Display the net billing amount after the discount.
e) Input the temperature in Fahrenheit and change into degrees.
f) Input three angles and check whether they form a triangle or not
g) Input a number between 1–7 and display the weekday based on the number entered.

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

You might also like