Skip to content

Update loops.py #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 29, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 47 additions & 10 deletions loops.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,53 @@

"""
# For loop
numbers = range(1,11)
### 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))

for number in numbers:
print(number)
##Output :
#Sum = 21
#Avg = 3.5
"""

# While loop
"""
### 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
"""

count = 0
### While Loop
fruits = ["banana", "apple", "orange", "kiwi"]
position = 0
while position < len(fruits):
print(fruits[position])
position = position + 1
print("reached end of list")

while count < 5:
print(count)
count += 1
##Output :
#banana
#apple
#orange
#kiwi
#reached end of list