Created
November 17, 2016 01:45
-
-
Save jjlumagbas/b1412c287501fa5a9509e758a8ecee8b to your computer and use it in GitHub Desktop.
While-loops in Python
This file contains hidden or 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
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