-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflowControlLoopExample.py
More file actions
63 lines (52 loc) · 1.06 KB
/
Copy pathflowControlLoopExample.py
File metadata and controls
63 lines (52 loc) · 1.06 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
54
55
56
57
58
59
60
61
62
63
#Flow control
# 2) Iterative Statement
# loops
#
# for loop
s = input("Enter a string")
count = 0
index = 0
for i in s:
print("the index of {} is".format(i),end=" ")
print(index)
index += 1
count += 1
print(count)
l =[10,20,30]
for x in l:
print(x)
for y in range(1,10):
print(y)
# while loop
# iteration know in advance then we should go for loop
# if we dont know then we can use while loop
# while condition:
# body
# Example 1 print 1 to 10 numbers
x = 1
while x<= 5:
print(x)
x+=1
#example 2
name =""
pwd = ""
while (name != 'naveen') and (pwd != 1234):
name= input("enter name:")
pwd = eval(input("enter password"))
print("Hello",name,"Good morning")
# Example 3 infinite loop
# i = 0
# while True:
# print(i)
# i+=1
#nested loops
#loop inside another loop
for i in range(4):
for j in range(4):
print(1,j)
#example
n = eval(input("enter number of rows:"))
for i in range(1,n+1): # i represents rows number
for j in range(1,i+1): # j represents the number of *
print("*",end= " ")
print()