Skip to content

Commit 369e399

Browse files
authored
Merge pull request #1 from rounak176/rounak176-patch-1
Update loops.py
2 parents 3e6431a + 992276a commit 369e399

File tree

1 file changed

+47
-10
lines changed

1 file changed

+47
-10
lines changed

loops.py

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,53 @@
1-
21
"""
3-
# For loop
4-
numbers = range(1,11)
2+
### For loop
3+
int_list = [1, 2, 3, 4, 5, 6]
4+
sum = 0
5+
for iter in int_list:
6+
sum += iter
7+
print("Sum =", sum)
8+
print("Avg =", sum/len(int_list))
59
6-
for number in numbers:
7-
print(number)
10+
##Output :
11+
#Sum = 21
12+
#Avg = 3.5
813
"""
914

10-
# While loop
15+
"""
16+
### Nested For loop
17+
for x in range(1,5):
18+
for y in range(1,5):
19+
print(x*y)
20+
21+
##Output :
22+
#1
23+
#2
24+
#3
25+
#4
26+
#2
27+
#4
28+
#6
29+
#8
30+
#3
31+
#6
32+
#9
33+
#12
34+
#4
35+
#8
36+
#12
37+
#16
38+
"""
1139

12-
count = 0
40+
### While Loop
41+
fruits = ["banana", "apple", "orange", "kiwi"]
42+
position = 0
43+
while position < len(fruits):
44+
print(fruits[position])
45+
position = position + 1
46+
print("reached end of list")
1347

14-
while count < 5:
15-
print(count)
16-
count += 1
48+
##Output :
49+
#banana
50+
#apple
51+
#orange
52+
#kiwi
53+
#reached end of list

0 commit comments

Comments
 (0)