From 56cd9767fb1a3b56d6473d3eb07444f72cd88933 Mon Sep 17 00:00:00 2001 From: Daniel Piron Date: Wed, 17 Feb 2021 11:38:45 -0500 Subject: [PATCH 1/2] Implement shell of hi lo game prompting user to play again --- 47 Hi-Lo/python/hilo.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 47 Hi-Lo/python/hilo.py diff --git a/47 Hi-Lo/python/hilo.py b/47 Hi-Lo/python/hilo.py new file mode 100755 index 00000000..d06d5003 --- /dev/null +++ b/47 Hi-Lo/python/hilo.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 + +QUESTION_PROMPT='? ' + +def play(): + print('HI LO') + print('CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n\n\n') + print('THIS IS THE GAME OF HI LO.\n') + print('YOU WILL HAVE 6 TRIES TO GUESS THE AMOUNT OF MONEY IN THE') + print('HI LO JACKPOT, WHICH IS BETWEEN 1 AND 100 DOLLARS. IF YOU') + print('GUESS THE AMOUNT, YOU WIN ALL THE MONEY IN THE JACKPOT!') + print('THEN YOU GET ANOTHER CHANCE TO WIN MORE MONEY. HOWEVER,') + print('IF YOU DO NOT GUESS THE AMOUNT, THE GAME ENDS.\n\n') + + total_winnings = 0 + while True: + print('PLAY AGAIN (YES OR NO)', end=QUESTION_PROMPT) + answer = input().upper() + if answer != 'YES': + break + + print('\nSO LONG. HOPE YOU ENJOYED YOURSELF!!!') + +if __name__ == '__main__': + play() From 4a45fe0e8ed0e04544b7de8f917f99e2dec11395 Mon Sep 17 00:00:00 2001 From: Daniel Piron Date: Wed, 17 Feb 2021 11:52:42 -0500 Subject: [PATCH 2/2] Implement hi-lo game logic --- 47 Hi-Lo/python/hilo.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/47 Hi-Lo/python/hilo.py b/47 Hi-Lo/python/hilo.py index d06d5003..370999a7 100755 --- a/47 Hi-Lo/python/hilo.py +++ b/47 Hi-Lo/python/hilo.py @@ -1,5 +1,7 @@ #!/usr/bin/env python3 +import random +MAX_ATTEMPTS = 6 QUESTION_PROMPT='? ' def play(): @@ -14,6 +16,30 @@ def play(): total_winnings = 0 while True: + print() + secret = random.randint(1, 100) + guessed_correctly = False + + for attempt in range(MAX_ATTEMPTS): + print('YOUR GUESS', end=QUESTION_PROMPT) + guess = int(input()) + + if guess == secret: + print('GOT IT!!!!!!!!!! YOU WIN {} DOLLARS.'.format(secret)) + guessed_correctly = True + break + elif guess > secret: + print('YOUR GUESS IS TOO HIGH.') + else: + print('YOUR GUESS IS TOO LOW.') + + if guessed_correctly: + total_winnings += secret + print('YOUR TOTAL WINNINGS ARE NOW {} DOLLARS.'.format(total_winnings)) + else: + print('YOU BLEW IT...TOO BAD...THE NUMBER WAS {}'.format(secret)) + + print('\n') print('PLAY AGAIN (YES OR NO)', end=QUESTION_PROMPT) answer = input().upper() if answer != 'YES':