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

Class 8 Chapter 7 Answers

Uploaded by

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

Class 8 Chapter 7 Answers

Uploaded by

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

Hecse answ

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

given condition becomes. True


iterate through the elements of lists.
dfor loop can be used to
t1mes will the loop run?
3. How many
i-2
while(i0):
j=i-1
b.3 d.0
a.2
if statement
4. Which one of the following is a valid Python d.ifa»=22

b.if (a>=2) C.if(a => 22)


a.ifa>-2: use to add an
alternative condition to an if
statement?

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 )

print('Sum is: ", sum1)


Sum is: 78
A n s . :

fornum in range-10, 0, 1):


printn u m )

A n s . - 1 0

-9
8
1
-6
5
-4
-3
-2
1

C. Answer the following questions:


1. What are the different types of control statements in Python?
There are 3 types of control statements in Python if, for and while
Ans.
2. When would you prefer for loop instead of while loop?

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

variables in while loop?


in the condition and
control While Loops. They are used
Ans. Sentry variables are used to manner as a human
values. It works in the similar
Compared to some other value or while loop's block.
like guard, helping form a barrier around the
sentry i.e., a
be
variables in while loop the loop will
If we don't change the value of Sentry
endless loop.
executed infinite times and it would be an
the editor
number between 1 to Go to
9.
Write a Python program to quess a
then the prompt appears
user guesses wrong
Note
U S e r is prompted to enter a quess. If
the will get a "Well guessed!"
on successtul guess, user
correct,
again until the guess is
will exit.
message, and the program counter outside the loop
without the
take the program
Heference: break helps to
condition becoming false

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****

Ans. for i in range(6):


print("")
for i in range(5):
print(",end=")

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

You might also like