Practice Problems - Loops
Example 1:
#While Loop Statement
#A while loop statement in Python programming language repeatedly executes a target statement as long as a given condition is true.
#Syntax of while loop :-
#while expression:
#statement(s)
#Here, statement(s) may be a single statement or a block of statements. The condition may be any expression, and true is any non-zero value. The loop iterates while the condition is true.
# Example:-
c = 1
while c <= 10 :
print("Hello World!")
c = c + 1
print("Python is Awesome")Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Python is Awesome
Example 2:
The count is: 0
The count is: 1
The count is: 2
The count is: 3
The count is: 4
The count is: 5
The count is: 6
The count is: 7
The count is: 8
Good bye!
Example 3:
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100,
Example 4:
0
1
2
0
Example 5:
1
2
3
4
5
6
Example 6:
File "", line 6 i + = 1 ^
Example 7:
10 9 8 7 6 5 4 3 2 1
Example 8:
Aston
Audi
McLaren
Example 9:
a
n
a
c
o
n
d
a
Example 10:
0
2
4
6
8
Example 11:
Enter number : 4
4 x 1 = 4
4 x 2 = 8
4 x 3 = 12
4 x 4 = 16
4 x 5 = 20
4 x 6 = 24
4 x 7 = 28
4 x 8 = 32
4 x 9 = 36
4 x 10 = 40
Example 12:
Do want to roll again : 5
Score : 3
Do want to roll again : 2
Score : 2
Do want to roll again :
Example 13:
Enter a Number : 55
Not Prime
Example 14:
Enter the no of terms5
1
2
3
5
8
Example 15:
Player1: p
Player2: r
Player1 is the Winner
Do want to continue (y/n) : n
Example 16:
Player2: r
Computer Choice was : s
Player Choice was : r
Player2 is the Winner
Do want to continue (y/n) : n
Last updated
Was this helpful?