The document discusses conditional and looping constructs in Python including for loops, while loops, range function, break and continue statements, and printing patterns using loops.
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
18 views
Conditional and Looping Constructs A
The document discusses conditional and looping constructs in Python including for loops, while loops, range function, break and continue statements, and printing patterns using loops.
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7
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? 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? i = 1 while True: if i%3 == 0: break print(i) 13. What is the output of the following? i=0 while i < 3: print(i) i += 1 else: print(0) 14. What is the output of the following? x = "abcdef" i = "i" while i in x: print(i, end=" ") 15. What is the output of the following? x = "abcdef" i = "a" while i in x: x = x[:-1] 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? d = {0: 'a', 1: 'b', 2: 'c'} 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? x = 2 for i in range(x): x += 1 print (x) 20. Rewrite following program using for loop t = 115 while t > 112: print(t) t=t-1 21. Rewrite following program using for loop i = 4 while i < 9: print(i) i = i+2 22. Rewrite following program using for loop no=3456 while no>0 : print(no%10) no=no/10
23. Rewrite following code fragment using while
loop (a) for i in range(5): print(i) (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): 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 factorial of a 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 which will find all such numbers which are divisible by 7 but are not a multiple of 5,between 2000 and 3200 (both included). 30. Suppose you need to print a pattern like this 1 12 123 1234 12345 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.
1. Когда Python работает в интерактивном режиме и отображает подсказку шеврона (>>>) - какой вопрос вам задает Python? Какой оператор Python вы хотите, чтобы я запустил?
1. Когда Python работает в интерактивном режиме и отображает подсказку шеврона (>>>) - какой вопрос вам задает Python? Какой оператор Python вы хотите, чтобы я запустил?