-
Write a Python program using a for loop to print the numbers from 1 to 5.
# Print numbers 1 to 5 using a for loop for num in range(1, 6): print('')
-
What is the output of this code?
for num in range(0, 10): print(num)
-
Which numbers will be printed?
for num in range(0, 5): print(num * 2)
-
Complete the code based on the scenario:
Suppose you are a teacher, and you have a list of student grades for a particular exam. You want to display each student’s grade to provide them with feedback.
# List of student grades grades = [85, 92, 78, 88, 95] # Display each student's grade for '' print(f"Student grade: {grade}")
-
What is the output of this code?
num = 1 while num <= 5: print(num) num += 1
-
What is the output of this code?
num = 5 while num >= 1: print(num) num -= 1
-
What is the output of this code?
num = 1 while num < 5: print(num) num += 1
Python Exercises for Loops
If you've faced difficulties with these exercises, take a look at Loops Module on my Python course.
You can also share 'Python Loops' Exercises on your:
X (Twitter) - Telegram - Linkedin - Facebook - or on your favorite platform...