Last active
August 29, 2015 14:23
-
-
Save seanballais/86a6f18fdd6f2588eea8 to your computer and use it in GitHub Desktop.
Solutions to the problems specified in http://www.reddit.com/r/learnprogramming/comments/39zfyh/how_do_i_learn_how_to_apply_code/
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 main(): | |
numberOfBottles = 99 | |
while numberOfBottles != 0: | |
firstVerseLine = getFirstOrLastLine(numberOfBottles) | |
print(firstVerseLine) | |
print(firstVerseLine + ", take one down pass it around.") | |
numberOfBottles = numberOfBottles - 1 | |
lastVerseLine = getFirstOrLastLine(numberOfBottles) | |
print(lastVerseLine + "\n") | |
def getFirstOrLastLine(numberOfBottles): | |
bottleQuantity = "bottle" | |
if numberOfBottles > 1 or numberOfBottles == 0: | |
bottleQuantity = "bottles" | |
verseLine = str(numberOfBottles) + " " + str(bottleQuantity) + " of beer on the wall" | |
return verseLine | |
if __name__ == "__main__": | |
main() |
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
import random, time | |
responses = [ | |
"No.", "Yes.", "Maybe.", "Time will explain.", "Be patient.", | |
"Maybe not.", "I am not sure", "In the future.", "Time will tell.", "Hmmm...", | |
"The vision is cloudy.", "Check back next time.", "I shouldn't probably say.", "Uhhhh...", "Meh!", | |
"Most likely.", "Unlikely.", "Your future self says yes.", "Your future self says no.", "You must look for an answer on your own." | |
] | |
execute = True | |
print("Magic 8 Ball by Sean Francis N. Ballais") | |
while execute: | |
question = input("Question: ") | |
print("Thinking...") | |
time.sleep(2.1) | |
index = random.randrange(0, 19) | |
print("Response: " + responses[index]) | |
again = input("Press ENTER for another question, or press 'Q' to exit. ") | |
if (again != ""): | |
execute = False | |
print("Thank you for using Magic 8 Ball.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment