Looping Test - 20 Marks
Looping Test - 20 Marks
1. Write a Python program to print all even numbers between 1 and 20 using a for loop.
2. Write a Python program to print series 25 16 9 4 1 using a for loop.
3. What is an infinite loop? Write a Python code snippet to demonstrate it.
4. Differentiate between for and while loops in Python with examples.
5. Write a Python program using a while loop to calculate the sum of all integers from 1 to 10.
6. Python's range() function is often used in for loops. Describe the role of range() and write
a code snippet using it to print all even numbers from 10 to 50.
7. Write a Python program to print the following pattern using nested loops: (1 mark each)
a. 1 b. 5 4 3 2 1 c. 88888
22 4321 66666
333 321 44444
4444 21 22222
55555 1 00000