-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflow_control.py
More file actions
113 lines (58 loc) · 1.21 KB
/
flow_control.py
File metadata and controls
113 lines (58 loc) · 1.21 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
num = 3
if num > 0:
print(num, "is a positive number.")
print("This is always printed.")
num = -1
if num > 0:
print(num, "is a positive number.")
print("This is also always printed.")
x=45
if x<34:
print("less")
elif x==34:
print("equal")
else:
print("greater")
digits = [0, 1, 5,"hello"]
for i in digits:
print(i)
else:
print("No items left.")
genre = ['pop', 'rock', 'jazz']
# iterate over the list using index
for i in range(len(genre)):
print("I like", genre[i])
n=10
sum = 0
i = 1
while i <= n:
sum = sum + i
i = i+1 # update counter
print(i)
# print the sum
print("The sum is", sum)
counter = 0
while counter < 3:
print("Inside loop")
counter = counter + 1
print(counter)
else:
print("Inside else")
# Use of break statement inside loop
for val in "string":
if val == "i":
break
print(val)
print("The end")
# Program to show the use of continue statement inside loops
for val in "string":
if val == "i":
continue
print(val)
print("The end")
# pass is just a placeholder for
# functionality to be added later.
sequence = {'p', 'a', 's', 's'}
for val in sequence:
# pass
print (val)