From c43c39453d2efd8239ecdfcbacbafb78e0b0331f Mon Sep 17 00:00:00 2001 From: Yichabod Date: Sat, 21 Jan 2017 20:46:33 +1300 Subject: [PATCH] Create Week2_guessing.game --- Week2_guessing.game | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Week2_guessing.game diff --git a/Week2_guessing.game b/Week2_guessing.game new file mode 100644 index 0000000..3599669 --- /dev/null +++ b/Week2_guessing.game @@ -0,0 +1,23 @@ +"""This is a programme that's supposed to be able to guess your secret number""" + +print('Please think of a number between 0 and 100!') +print('Is your secret number 50?') +response = input(" Enter 'h' to indicate the guess is too high. Enter 'l' to indicate the guess is too low. Enter 'c' to indicate I guessed correctly.") +guess = 50 + +while response == "l" or "h" or "c": + if response == "l": + guess = int(round(guess*1.5)) + print('Is your secret number', guess, end='?') + response = input("Enter 'h' to indicate the guess is too high. Enter 'l' to indicate the guess is too low. Enter 'c' to indicate I guessed correctly.") + if response == "h": + guess = int(guess/2) + print('Is your secret number', guess, end='? ') + response = input("Enter 'h' to indicate the guess is too high. Enter 'l' to indicate the guess is too low. Enter 'c' to indicate I guessed correctly.") + + if response == "c": + print('Game over. Your secret number is ',end=str(guess)) + break + if response != "h" or response != "l" or response != "c": + print('Sorry, I did not understand your input.') + input("Enter 'h' to indicate the guess is too high. Enter 'l' to indicate the guess is too low. Enter 'c' to indicate I guessed correctly.")