CONDITIONAL AND LOOPING CONSTRUCTS
ASSIGNMENTS
1. What is the use of range() function in python?
2. else clause is available with if as well as loop construct, can you differentiate the use of else in both.
3. What is empty statement?
4. What is determinable and non determinable loop in python?
5. What are jump statements in python?
6. What is entry control loop? 7. What is named condition?
8. What is the output of the following program?
x = ['dc', 'ba'] for i in x:
i.upper()
print(x)
9. What is the output of the following program? x = 321
for i in x:
print(i)
10. What is the output of the following program?
for i in [4, 3, 2, 1][::-1]:
print (i)
11. What is the output of the following program?
print (i)
11. What is the output of the following program?
numbers = [6, 5, 3, 8, 4, 2, 5, 4, 11]
sum = 0
for val in numbers: sum = sum+val
print("The sum is", sum)
12. What is the output of the following?
sum = 0
for val in numbers: sum = sum+val
print("The sum is", sum)
12. What is the output of the following?
i = 1
while True:
if i%3 == 0:
while True:
if i%3 == 0:
break
print(i)
print(i)
13. What is the output of the following?
i = 0
while i < 3:
print(i)
while i < 3:
print(i)
i += 1
else:
print(0)
14. What is the output of the following?
else:
print(0)
14. What is the output of the following?
x = "abcdef"
i = "i"
i = "i"
while i in x:
print(i, end=" ")
15. What is the output of the following?
print(i, end=" ")
15. What is the output of the following?
x = "abcdef"
i = "a"
while i in x:
i = "a"
while i in x:
x = x[:-1]
print(i, end = " ")
16. What is the output of the following?
print(i, end = " ")
16. What is the output of the following?
x = 123
for i in x:
print(i)
17. What is the output of the following?
for i in x:
print(i)
17. What is the output of the following?
d = {0: 'a', 1: 'b', 2: 'c'}
for i in d:
print(i)
18. What is the output of the following?
for i in d:
print(i)
18. What is the output of the following?
d = {0: 'a', 1: 'b', 2: 'c'}
for x in d.keys():
print(d[x])
19. What is the output of the following?
for x in d.keys():
print(d[x])
19. What is the output of the following?
x = 2
for i in range(x):
for i in range(x):
x += 1
print (x)
20. Rewrite following program using for loop
print (x)
20. Rewrite following program using for loop
t = 115
while t > 112:
print(t)
while t > 112:
print(t)
t=t-1
21. Rewrite following program using for loop
i = 4
while i < 9:
21. Rewrite following program using for loop
i = 4
while i < 9:
print(i)
i = i+2
22. Rewrite following program using for loop
i = i+2
22. Rewrite following program using for loop
no=3456
while no>0 :
print(no%10)
while no>0 :
print(no%10)
no=no/10
23. Rewrite following code fragment using while loop
23. Rewrite following code fragment using while loop
(a) for i in range(5):
print(i)
(b)
for num in range(2, 10):
(b)
for num in range(2, 10):
if num % 2 == 0:
print("Found an even number", num)
continue
print("Found a number", num)
(c)
for x in range(10):
print("Found an even number", num)
continue
print("Found a number", num)
(c)
for x in range(10):
if x % 2 == 0:
continue
print(x)
24. Take 10 integers from keyboard using loop and print their average value on the screen.
25. Print the following patterns using loop :
*
***
*****
***
*
26. Write a program to calculate
24. Take 10 integers from keyboard using loop and print their average value on the screen.
25. Print the following patterns using loop :
*
***
*****
***
*
26. Write a program to calculate
- factorial of a number.
- fibonacci series
- sum 10 natural number
27. Calculate the sum of digits of a number given by user.
E.g.-
INUPT : 123 OUPUT : 6
INUPT : 12345 OUPUT : 15
28. Write a program to print all prime number in between 1 to 100.
29. Write a program to check the given number is Armstrong or not.
EG: 153= 1*1*1+5*5*5+3*3*3
=1+125+27 =153
153=153 it is armstrong number
30. Suppose you need to print a pattern like this
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Write python program for it.
31. How many times will the following code print "Welcome to Python"?
count = 0
while count < 10: print("Welcome to Python") count += 1
32. What is the output of the following code? x = 0
while x < 4:
x = x + 1 print("x is", x)
33. Write a Python program to construct the following pattern, using a nested for loop.
*
* *
* * *
* * * *
34. Write a Python program to create the multiplication table (from 1 to 10) of a number.
30. Suppose you need to print a pattern like this
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Write python program for it.
31. How many times will the following code print "Welcome to Python"?
count = 0
while count < 10: print("Welcome to Python") count += 1
32. What is the output of the following code? x = 0
while x < 4:
x = x + 1 print("x is", x)
33. Write a Python program to construct the following pattern, using a nested for loop.
*
* *
* * *
* * * *
34. Write a Python program to create the multiplication table (from 1 to 10) of a number.
What is determinable and non determinable loop in python?
ReplyDeletewhat is the answer for the above question
What is the answer of question 22
ReplyDelete