Skip to content

Instantly share code, notes, and snippets.

@TomColBee
Created June 17, 2018 16:27
Show Gist options
  • Save TomColBee/67276c3dd7ec920c99be68c2ca565584 to your computer and use it in GitHub Desktop.
Save TomColBee/67276c3dd7ec920c99be68c2ca565584 to your computer and use it in GitHub Desktop.
Python Bible - Simple While Loop examples
# set x eq to 1
x= 1
# prints if x is less than 11
while x < 11:
print(x)
x = x+1
# prints if x is even but less than 100
while x < 100:
if x % 2 == 0:
print(x)
x = x + 1
# prints if x is odd but less than 100
while x < 100:
if x % 2 == 1:
print(x)
x = x + 1
# create an empty list L
L = []
# while length of the list is less than 3, then ask to add a new name to list.
while len(L) < 3:
new_name = input("Please add a new name: ")
L.append(new_name)
# when length of L >= 3 then print "Sorry list is full"
print("Sorry list is full")
print(L)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment