Teachers and Examiners (CBSESkillEduction) collaborated to create the Flow of Control in Python Class 11 Questions and Answers. All the important Information are taken from the NCERT Textbook Computer Science (083) class 11.
Flow of Control in Python Class 11 Questions and Answers
1. What is the difference between else and elif construct of if statement?
Answer – Elif is an acronym for else if. We can check for several expressions with this. If the if condition is False, the next elif block’s condition is checked, and so on. The body of else is executed if all the conditions are false.
2. What is the purpose of range() function? Give one example.
Answer – Python comes with a built-in function called range(). It is used to generate a list of numbers from the specified start value to the specified stop value (excluding stop value). For the purpose of creating a number series, this is frequently used in for loops.
3. Differentiate between break and continue statements using examples.
Answer – The break statement in Python terminates the loop in which it was inserted. A single loop iteration is skipped using a continue statement in Python. In either a for or a while loop, you can use the break and continue statements. You could want to stop a loop in its tracks or skip a specific iteration.
Example –
Example:
for num in range(1,10):
print (num)
OUTPUT:
1
2
3
4
5
6
7
8
9
10
Flow of Control in Python Class 11 Questions and Answers
4. What is an infinite loop? Give one example.
Answer – The test condition for the loop must finally become false according to the statement contained in the body of the loop; otherwise, the loop will continue indefinitely. So, a loop that never ends is known as an infinite loop.
Example –
i = -1
while(i != 1):
print(1)
i -= 1
5. Find the output of the following program segments:
(i)
a = 110
while a > 100:
print(a)
a -= 2
(ii)
for i in range(20,30,2):
print(i)
(iii)
country = ‘INDIA’
for i in country:
print (i)
(iv)
i = 0; sum = 0
while i < 9:
if i % 4 == 0:
sum = sum + i
i = i + 2
print (sum)
(v)
for x in range(1,4):
for y in range(2,5):
if x * y > 10:
break
print (x * y)
(vi)
var = 7
while var > 0:
print (‘Current variable value: ‘, var)
var = var -1
if var == 3:
break
else:
if var == 6:
var = var -1
continue
print (“Good bye!”)
Answer –
(i) Output
110
108
106
104
102
(ii) Output
OUTPUT:
20
22
24
26
28
(iii) Output
OUTPUT:
I
N
D
I
A
(iv) OUTPUT
12
(v) OUTPUT
2
3
4
4
6
8
6
9
(vi) OUTPUT
Current variable value: 7
Current variable value: 5
Good bye!
Current variable value: 4
Flow of Control in Python Class 11 Questions and Answers
1. Write a program that takes the name and age of the user as input and displays a message whether the user is eligible to apply for a driving license or not.
(the eligible age is 18 years).
Answer –
age = int(input(“Enter your age : “))
if age >= 18:
print(“Eligible for Voting”)
else:
print(“Not Eligible for Voting”)
Output
Enter your age : 20
Eligible for Vote
2. Write a function to print the table of a given number. The number has to be entered by the user.
Answer –
num = int(input(“Enter the number for table: “))
print(“Table – “, num);
for a in range(1,11):
print(num,” × “,a,” = “,(num*a))
Enter the number for table: 8
Table – 8
8 × 1 = 8
8 × 2 = 16
8 × 3 = 24
8 × 4 = 32
8 × 5 = 40
8 × 6 = 48
8 × 7 = 56
8 × 8 = 64
8 × 9 = 72
8 × 10 = 80
3. Write a program that prints minimum and maximum of five numbers entered by the user.
Answer –
max = 0
min = 0
for a in range(0,5):
x = int(input(“Enter the number: “))
if a == 0:
min = max = x
if(x < min):
min = x
if(x > max):
max = x
print(“The largest number is “,max)
print(“The smallest number is”,min)
Output
Enter the number: 63
Enter the number: 21
Enter the number: 49
Enter the number: 75
Enter the number: 25
The largest number is 75
The smallest number is 21
Flow of Control in Python Class 11 Questions and Answers
4. Write a program to check if the year entered by the user is a leap year or not.
Answer –
year = int(input(‘Enter year : ‘))
if (year%4 == 0 and year%100 != 0) or (year%400 == 0) :
print(year, “is a leap year”)
else :
print(year, “is not a leap year”)
Output
Enter year : 2000
2000 is a leap year
5. Write a program to generate the sequence: –5, 10, –15, 20, –25….. upto n, where n is an integer input by the user.
Answer –
num = int(input(“Enter the number: “))
for a in range(1,num+1):
if(a%2 == 0):
print(a * 5, end=”,”)
else:
print(a * 5 * (-1),end=”,”)
Output
Enter the number: 12
> 23
-5,10,-15,20,-25,30,-35,40,-45,50,-55,60,23
6. Write a program to find the sum of 1+ 1/8 + 1/27……1/n3, where n is the number input by the user.
Answer –
sum = 0
n = int(input(“Enter the number: “))
for a in range(1,n+1):
sum = sum + (1/pow(a,3))
print(“The sum of series is: “,round(sum,2))
Output
Enter the number: 10
The sum of series is: 1.2
Flow of Control in Python Class 11 Questions and Answers
7. Write a program to find the sum of digits of an integer number, input by the user.
Answer –
sum = 0
n = int(input(“Enter the number: “))
while n > 0:
num = n % 10
sum = sum + num
n = n//10
print(“The sum of digits is”,sum)
Output
Enter the number: 325
The sum of digits is 10
8. Write a function that checks whether an input number is a palindrome or not.
[Note: A number or a string is called palindrome if it appears same when written in reverse order also. For example, 12321 is a palindrome while 123421 is not a palindrome]
Answer –
rev = 0
n = int(input(“Enter the number: “))
temp = n
while temp > 0:
num = (temp % 10)
rev = (rev * 10) + num
temp = temp // 10
if(n == rev):
print(“Palidrome”)
else:
print(“Not a Palindrome”)
Output
Enter the number: 121
Palidrome
Flow of Control in Python Class 11 Questions and Answers
9. Write a program to print the following patterns:
![python patterns](https://cbseskilleducation.com/wp-content/uploads/2022/10/python-patterns.jpg)
Answer –
i)
n = 3
for i in range (1, n + 1):
blank = (n – i)*” “
count = (2 * i – 1)*”*”
print(blank,count)
for j in range(n – 1, 0, -1):
blank = (n – j)*” “
star = (2 * j – 1)*”*”
print(blank, count)
ii)
n = 5
for i in range (1, n + 1):
blank = (n – i) * ” “
print(blank, end = ” “)
for k in range(i, 1, -1):
print(k, end = ” “)
for j in range(1, i + 1):
print(j, end = ” “)
print()
iii)
n = 5
for i in range (n, 0, -1):
blank = (n – i)*” “
print(blank, end=” “)
for j in range(1, i + 1):
print(j, end=” “)
print()
iv)
n = 3
k = 0
for i in range (1, n + 1):
blank = (n – i)*” “
print(blank, end=’ ‘)
while (k != (2 * i – 1)) :
if (k == 0 or k == 2 * i – 2) :
print(‘*’, end= “”)
else :
print(‘ ‘, end = “”)
k = k + 1
k = 0
print()
for j in range (n – 1, 0, -1):
blank = (n – j)*” “
print(blank, end=” “)
k = (2 * j – 1)
while (k > 0) :
if (k==1 or k == 2*j-1):
print(“*”,end=””)
else:
print(” “,end=””)
k = k – 1
print()
Flow of Control in Python Class 11 Questions and Answers
10. Write a program to find the grade of a student when grades are allocated as given in the table below.
Percentage of Marks Grade
Above 90% – A
80% to 90% – B
70% to 80% – C
60% to 70% – D
Below 60% – E
Percentage of the marks obtained by the student is input to the program.
Answer –
n = int(input(‘Enter the percentage of the marks: ‘))
if(n > 90):
print(“A”)
elif(n > 80):
print(“B”)
elif(n > 70):
print(“C”)
elif(n >= 60):
print(“D”)
else:
print(“E”)
Output
Enter the percentage of the marks: 99
A
omputer Science Class 11 Notes
- Unit 1 : Basic Computer Organisation
- Unit 1 : Encoding Schemes and Number System
- Unit 2 : Introduction to problem solving
- Unit 2 : Getting Started with Python
- Unit 2 : Conditional statement and Iterative statements in Python
- Unit 2 : Function in Python
- Unit 2 : String in Python
- Unit 2 : Lists in Python
- Unit 2 : Tuples in Python
- Unit 2 : Dictionary in Python
- Unit 3 : Society, Law and Ethics
Computer Science Class 11 MCQ
- Unit 1 : Basic Computer Organisation
- Unit 1 : Encoding Schemes and Number System
- Unit 2 : Introduction to problem solving
- Unit 2 : Getting Started with Python
- Unit 2 : Conditional statement and Iterative statements in Python
- Unit 2 : Function in Python
- Unit 2 : String in Python
- Unit 2 : Lists in Python
- Unit 2 : Tuples in Python
- Unit 2 : Dictionary in Python
- Unit 3 : Society, Law and Ethics
Computer Science Class 11 NCERT Solutions
- Unit 1 : Basic Computer Organisation
- Unit 1 : Encoding Schemes and Number System
- Unit 2 : Introduction to problem solving
- Unit 2 : Getting Started with Python
- Unit 2 : Conditional statement and Iterative statements in Python
- Unit 2 : Function in Python
- Unit 2 : String in Python
- Unit 2 : Lists in Python
- Unit 2 : Tuples and Dictionary in Python
- Unit 3 : Society, Law and Ethics