Skip to content

Instantly share code, notes, and snippets.

@jjlumagbas
Created November 17, 2016 01:45
Show Gist options
  • Save jjlumagbas/b1412c287501fa5a9509e758a8ecee8b to your computer and use it in GitHub Desktop.
Save jjlumagbas/b1412c287501fa5a9509e758a8ecee8b to your computer and use it in GitHub Desktop.
While-loops in Python
def foo(x, y):
current = x + y
while (current < 100):
current = current + x + y
print(current)
print("loop finished")
foo(10, 10)
def get_yn ():
response = ""
while (response != "y" and response != "n"):
response = input("Type y or n to continue: ")
return response
valid = False
while (not valid):
s = input ("Enter a password: ")
valid = (len(s) == 5 and s[:2] == "xy")
# 􏰀 A.xyz
# 􏰀 B. abcxy
# 􏰀 C. xyabc
# 􏰀 D. More than one of the above passwords get us out of the loop
# 􏰀 E. None; the loop never executes and no passwords are obtained
def double_money(deposit):
years = 0
while ():
#...
year = year + 1
return years
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment