Class 8 Chapter 7 Answers
Class 8 Chapter 7 Answers
correct
hoosethe
se
thich
f of thefollowing is not used as loop in Python?
a.for loop b. while loop
c. do-while loop d . None of the above
hich ofthe following is False regarding loops in Python?
2
a. oops are used to perform certain tasks repeatedly.
While loop is used when multiple statements are to executed repeatedly until the
given condition becomes. False
While loop is used when mutiple statements are to executed repeatedly until the
would you
5. What keyword
C.elif d . None oftheabove
a. else if b.elseif
control structure:
6. In a Python program, a
program-specific
data structures
a. Defines statements in the program
the
b. Directs the order
of execution of it terminates
starts and after
the program
C. Dictates what
happens before
the others?
d. None of the above different output from
will give
following Python code b.forj in [0,1,2,3,4:
7Which of the
a. for i in range(0,5): print()
in range(0,5,1):
print() d .for
c. for k in [0,1,2,3,4,5 print()
print(k) to b?
will checkif a is equal c Ld.if a
==b
c .ifa
===
W h i c h statement
a. if a =b:
a==b:
b.if
137
9. A while loop in Python is used for what type of iteration
c. definite d.indeterminate
a. indefinite b. discriminant
10. What will be the output of the following code?
X= 12
for i in x
print()
a..12 b.12
C. Error d.None of theabove
B. Find the output of the following.
1. a= True
b False
c False
d if a or b and c:
print ('COMPUTING)
else:
print (TECHNOLOGY")
Ans.: COMPUTING
2. for i in range(2):
print( 1)
for i in range(4,6):
print( )
Ans.: 0
5
3. numb = 0
while numb< 5:
print(numb)
Ans. 0would be displayed infinite times
4. Sum1 0
n 12
fori in range(1, n + 1,1):
sum1+i
138
p r i n t ( " i n )
A n s . - 1 0
-9
8
1
-6
5
-4
-3
-2
1
Ans.: For loop is recommended to use only when you know exactly how many times the loop
will execute.
you don't change the value of Sentry
3. What Sentry variables? What would happen if
are
K39
Ans. import random
no=random.randint(1,10)
while(True)
guess=int(input("Guess any number from 1-10)
if guess==no:
print("Well guessed")
break
w r i t e a Python program to count the number of even and odd numbers from a
numbers.
Sample numbers numbers = (1, 2, 3, 4, 5, 6, 7, 8, 9)
Expected Output:
Number of even numbers: 5
Number of odd numbers: 4
Ans.: numbers=(1,2,4,2,7,7,5,21,23,89)
even=0
odd=0
for i in numbers:
if i%2==0
even=even+1
else
odd=odd+1
print("Number of even numbers:",even)
print "Number of odd numbers:",odd)
6. Write a Python program to print alphabet
pattern T.
Expected Output:
k****
140
F2
and ye5
ifx1
print(hello)
print(*40)
A2
digit=int/
inputfenter any number))
if digit 9 and digite=99;
print Two digit number)
elf digits 99 and digite=999
print Three digit number)
elif digit> 999 and digit<=9999:
print(Ffour digit number)
else
print number is «9 or >=9999)
nilerstondin