Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python3
- # if anyone actually reads this, thank you for your work!!
- epsilon = 1
- low = 0
- high = 100
- ans = ((low + high) // 2)
- num = 0
- def guess(answer, margin, bottom, top, number):
- stop = False
- while stop == False:
- response = input(
- "Is your secret number {}?\nEnter 'h' to indicate the guess is too high. Enter 'l' to indicate the guess is too low. Enter 'c' to indicate I guessed correctly. ".format(answer))
- if response == 'l':
- bottom = answer
- elif response == 'h':
- top = answer
- elif response == 'c':
- print("Game Over. Your secret number was:", end=' ')
- print(answer)
- stop = True
- break
- else:
- print("I'm sorry, I did not understand your input.")
- continue
- answer = ((top + bottom) // 2)
- while not 100 > num > 0:
- try:
- num = int(input("Please think of a number between 0 and 100!"))
- except ValueError:
- print("not a valid input")
- num = 0
- continue
- guess(ans, epsilon, low, high, num)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement