-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloop17,18,35.py
More file actions
45 lines (43 loc) · 867 Bytes
/
loop17,18,35.py
File metadata and controls
45 lines (43 loc) · 867 Bytes
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
#For loop
#iterating over a string:
name = 'Abhishek'
for i in name:
print(i, end=", ")
print()
#iterating over a list:
lst=["suraj",5,True,3.14]
for i in lst:
print(i, end=", ")
print()
#for a specific number of times
for i in range(5):
print(i,end=", ")
print()
for i in range(4,10,2):
print(i,end=", ")
print()
#while loop
count = 5
while (count > 0):
print(count,end=" ")
count = count - 1
#Else with While Loop
count=int(input("Enter a Number: "))
while (count > 0):
print(count,end=" ")
count = count - 1
else:
print("Count is Zero")
print()
#emulate do while loop
while True:
number = int(input("Enter a positive number: "))
print(number)
if not number > 0:
break
#for loop with else
for x in range(5):
print ("iteration no {} in for loop".format(x+1))
else:
print ("else block in loop")
print ("Out of loop")