forked from maxg203/Python-for-Beginners
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloops.py
More file actions
53 lines (48 loc) · 594 Bytes
/
loops.py
File metadata and controls
53 lines (48 loc) · 594 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
46
47
48
49
50
51
52
53
"""
### For loop
int_list = [1, 2, 3, 4, 5, 6]
sum = 0
for iter in int_list:
sum += iter
print("Sum =", sum)
print("Avg =", sum/len(int_list))
##Output :
#Sum = 21
#Avg = 3.5
"""
"""
### Nested For loop
for x in range(1,5):
for y in range(1,5):
print(x*y)
##Output :
#1
#2
#3
#4
#2
#4
#6
#8
#3
#6
#9
#12
#4
#8
#12
#16
"""
### While Loop
fruits = ["banana", "apple", "orange", "kiwi"]
position = 0
while position < len(fruits):
print(fruits[position])
position = position + 1
print("reached end of list")
##Output :
#banana
#apple
#orange
#kiwi
#reached end of list