Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- epsilon=0.1
- high=100.0
- low=0.0
- ans=(high+low)/2
- while True:
- try:
- x=float(input("Please think of a number between 0 and 100!"))
- break
- except ValueError:
- print("That wasn't a number. Try again.")
- while x>=100:
- print("The number you typed in was out of range.")
- x=float(input("Please think of a number between 0 and 100!"))
- while x<0:
- print("The number you typed in was out of range.")
- x=float(input("Please think of a number between 0 and 100!"))
- else:
- while ans>x+epsilon or ans<x-epsilon:
- print("Is your secret number",ans,"?")
- a=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.")
- for z in a:
- if z=='h':
- high=ans
- ans=(high+low)/2
- if z=='l':
- low=ans
- ans=(high+low)/2
- if z=='c':
- print("You're a lyer!")
- if z!='h' and z!='l' and z!='c':
- print("Sorry, I did not understand your input.")
- print("Game over: Your secret number was",round(ans))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement