Skip to content

Instantly share code, notes, and snippets.

@jjlumagbas
Created November 24, 2016 03:21
Show Gist options
  • Save jjlumagbas/d08ef200a81ecf425fdf9c7cf0392f76 to your computer and use it in GitHub Desktop.
Save jjlumagbas/d08ef200a81ecf425fdf9c7cf0392f76 to your computer and use it in GitHub Desktop.
Using for i to iterate through a list
def display(lst):
for el in lst:
print(el)
# display(["Hi", "Hello", "Bye"])
def display2(lst):
for i in range(0, len(lst)):
print(lst[i])
greets = ["Hi", "Hello", "Bye", "See you"]
# display2(greets)
# display2(["Hi", "Hello"])
def excited(lst):
for i in range(0, len(lst)):
lst[i] = lst[i] + "!"
# print(greets)
# excited(greets)
# print(greets)
def greetNames(greets, names):
for i in range(0, len(greets)):
print(greets[i] + " " + names[i] + "!")
names = ["Joshua", "Dennis", "Nisha", "Janice"]
# greetNames(greets, names)
def showHeavier(rat1, rat2):
count = 0
for i in range(0, len(rat1)):
rat1w = rat1[i]
rat2w = rat2[i]
if (rat1w > rat2w):
count = count + 1
return count
rat1 = [150, 155, 143, 160, 165]
rat2 = [90, 100, 144, 160, 165]
print(showHeavier(rat1, rat2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment