Created
June 17, 2018 16:27
-
-
Save TomColBee/67276c3dd7ec920c99be68c2ca565584 to your computer and use it in GitHub Desktop.
Python Bible - Simple While Loop examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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