-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path09_Loops_While.py
More file actions
53 lines (45 loc) · 1.03 KB
/
09_Loops_While.py
File metadata and controls
53 lines (45 loc) · 1.03 KB
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
##Loops:Loops in Python are used to repeat actions efficiently. The main types are For loops (counting through items) and While loops (based on conditions).
##Life is Loop
##While loop
counter=0
while counter <6:
counter+=1
print("Iteration no", format(counter))
print("End of While Loop")
##WAP toprint no between 1 to 20
num=1
while num<=20:
print(format(num))
num+=1
#Wap to print the content of a list using while loops
numList=([5,9,3,0])
index=0
while (index<len(numList)):
print(numList[index])
index+=1
##While else loop
counter=1
while counter <6:
print("Iteration no", format(counter))
counter+=1
else:
print("From else Block")
print("End of While Loop")
##While break loop
var = 10
while var > 0:
print ('Current variable value :', var)
var = var -1
if var == 5:
break
print ("Good bye!")
##While contiinue loop
num = 60
print ("Prime factors for: ", num)
d=2
while num > 1:
if num%d==0:
print (d)
num=num/d
continue
d=d+1