Skip to content

Commit 6b42ab4

Browse files
initialcommit
1 parent 609be62 commit 6b42ab4

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

11-WhileLoop.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#Python While Loop
2+
'''
3+
i=1
4+
while(i<15)
5+
{
6+
statements
7+
}
8+
1,2,3,4,5
9+
1+4+9+16+25=55
10+
'''
11+
#Example
12+
n=5
13+
s=1
14+
summation=0
15+
while s<=n:
16+
summation = summation + s**2
17+
s+=1
18+
print("The sum of squares is", summation)
19+
20+
#Multiplication Table using While Loop
21+
num = 5
22+
counter = 1
23+
# we will use a while loop for iterating 10 times for the
24+
# multiplication table
25+
print("The Multiplication Table of: ", num)
26+
while counter <= 10: # specifying the condition
27+
ans = num * counter
28+
print (num, 'x', counter, '=', ans)
29+
counter += 1 # expression to increment the counter
30+
31+
#Python While Loop Multiple Conditions
32+
num1 = 17
33+
num2 = -12
34+
35+
while num1 > 5 and num2 < -5 : # multiple conditions in a single while loop
36+
num1 -= 2
37+
num2 += 3
38+
print( (num1, num2) )
39+
40+
#Multiple conditions with an OR operator
41+
num1 = 17
42+
num2 = -12
43+
44+
while num1 > 5 or num2 < -5 :
45+
num1 -= 2
46+
num2 += 3
47+
print( (num1, num2) )
48+
49+
50+

0 commit comments

Comments
 (0)