# 70+(solved) Important Practice Questions of Loops in Python

Share with others

## Practice Questions of Loops in Python — Test 1

```Q1. Write the output of the following:

1.  for i in "Myblog":
print (i, '?')

M ?
y  ?
b ?
l  ?
o ?
g ?

2.  for i in range(5):
print(i)

0
1
2
3
4

3. for i in range(10,15):
print(i)

10
11
12
13
14

Q2. Write a program to print first 10 natural number.
for i in range(1,11):
print(i)

Q3. Write a program to print first 10 even numbers.
for i in range(2,22,2):
print(i)

Q4. Write a program to print first 10 odd numbers.
for i in range(1,21,2):
print(i)

Q5. Write a program to print first 10 even numbers in reverse order.
for i in range(20,0,-2):
print(i)

Q6. Write a program to print table of a number accepted from user.
num = int(input("Enter any number")
for i in range(1,11):
print(num*i)

Q7. Write a program to display product of the digits of a number accepted from the user.

num=int(input("Enter any number"))
p=1
while(num):
r=num%10
p=p*r
num=num//10
print("Product of digits is",p)

Q8. Write a program to find the factorial of a number.
num=int(input("Enter any number"))
f=1
for i in range(1,num+1):
f=f*i
print("Factorial is",f)

Q9. Write a program to find the sum of the digits of a number accepted from user
num=int(input("Enter any number"))
s=0
while(num):
r=num%10
s=s+r
num=num//10
print("Sum of digits is",s)

Q10. Write a program to check whether a number is prime or not.
num=int(input("Enter any number"))
f=0
if num==1 or num==0:
f=1
for i in range(2,num):
if num%i==0:
f=1
if f==1:
print("Number is not prime")
else:
print("Number is prime")```

## Practice Questions of Loops in Python — Test 2

```Q1. Write the output of the following

1. for i in (1,10):
print(i)
1
10

2. for i in (5,9):
print(i)
5
9

3. for i in range(2,7):
print(i)
2
3
4
5
6

4. for i in "csiplearninghub":
print(i)
c
s
i
p
l
e
a
r
n
i
n
g
h
u
b

5. for i in "python":
print(i, end=' ')
p y t h o n

6. for i in "python":
print(i, end=='?')
p?y?t?h?o?n?

7. for i in "python":
print(i, '?\$')
p?\$y?\$t?\$h?\$o?\$n?\$

8. for i in (1,2,3,4):
print(i)
1
2
3
4

9. for i in (3,4,7):
print(i)
3
4
7

10. for i in range(2,10,2):
print(i)
2
4
6
8
```

## Practice Questions of Loops in Python — Test 6

Q1. Write the output of the following.

a=5
while a>0:
print(a)
a=a-1

`Show AnswerAns.54321`

Q2. for loop statement is terminated by symbol ___________

`Show AnswerAns. Semicolon(;)`

Q3. What is the difference between break and continue statements?

`Show AnswerAns. break statement terminates the loop as the condition matches. for example.a=5while a>0:   a=a-1   if a==3: #as this condition matches it terminates the loop      break   else:      print(a)Output : 4Continue statement is used to skip a particular condition. for examplea=5while a>0:   a=a-1   if a==3: #as this condition matches it goes to the next condition of the loop      continue   else:      print(a)Output : 4210`

Q4. Convert the following loop into for loop :
x = 4
while(x<=8):
print(x*10)
x+=2

`Show AnswerAns.for x in range(4,9,2):    print(x*10)`

Q5. Write the output of the following:
for k in range(10,20,4):
print(k)

`Show AnswerAns.101418`

Q6. Find errors in the following code:
x = input(“Enter value”)
for k in range[0,20]
if x=k
print(x+k)
else:
Print(x-k)

`Show AnswerAnsx = input("Enter value")for k in range(0,20):    if x==k:       print(x+k)    else:       print(x-k)`

Q7. Write the output of the following:

x=3
if x>2 or x<5 and x==6:
print(“Bye”)
else:
print(“Thankyou”)

Q8. Write the output of the following:

x,y=2,4
if(x+y==10):
print(“Thankyou”)
else:
print(“Bye”)

Q9. Write the output of the following:

x=10
y=1
while x>y:
x=x-4
y=y+3
print(x)

`Show AnswerAns.62`

Q10. Write the output of the following:
for x in range(3):
for y in range(2):
print(“Practice Questions of loops in python”)
print()

`Show AnswerAns.Practice Questions of loops in pythonPractice Questions of loops in pythonPractice Questions of loops in pythonPractice Questions of loops in pythonPractice Questions of loops in pythonPractice Questions of loops in python`

## Practice Questions of Loops in Python — Test 7

Q1. What do you mean by jump statement?

Q2. What is nested loop?

Q3. Write a program to print the following pattern.

1    2     3    4

1    2     3

1   2

1

Q4. Write a program to print the following pattern.

A

B    C

D    E    F

G    H    I    J

Q5. Write a program to print the following pattern.

A    A    A    A

A    A    A    A

A    A    A    A

A    A    A    A

Q6. Write a program to convert temperature in Fahrenheit to Celsius.

Q7. Write a program to print the factorial of a number.

Q8. Write a program to find the sum of digits of a number.

Q9. Accept two numbers from the user and display sum of even numbers between them(including both)

Q10. Write a program to reverse a number.

Class 12 Computer Science Sample Paper 2020-2021.

Class 12 Computer Science Sample Paper Marking Scheme

Class 12 Computer Science Test Series

Share with others
error: Content is protected !!