Advertisement
Guest User

Untitled

a guest
Jul 24th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.44 KB | None | 0 0
  1. from time import sleep as s
  2.  
  3.  
  4. rng = [0, 100]
  5.  
  6.  
  7. def guess(r):
  8.     mid = sum(r) // 2
  9.     prompt = input(f"I think your number is {mid}. ").lower()
  10.     while " " in prompt:
  11.         prompt = prompt.replace(" ", "")
  12.     if r[0] == mid - 1 and r[1] == mid + 1 and (prompt == "high" or prompt == "low"):
  13.         print("I concluded that you are a liar")
  14.         print(f"There is only one number between {r[0]} and {r[1]}")
  15.         print("I don't want to continue this game")
  16.     elif (r[0] == mid or r[1] == mid) and (prompt == "high" or prompt == "low"):
  17.         print("I concluded that you are a liar")
  18.         print(f"There are no numbers between {r[0]} and {r[1]}")
  19.         print("I don't want to continue this game")
  20.     else:
  21.         if prompt == "low":
  22.             r[0] = mid
  23.             print("Okay then. I'll try something higher")
  24.             guess(r)
  25.         elif prompt == "high":
  26.             r[1] = mid
  27.             print("Okay then. I'll try something lower")
  28.             guess(r)
  29.         elif prompt == "correct":
  30.             if mid == 50:
  31.                 print("You gotta be kidding me! Nobody thinks of 50!")
  32.                 print("It's the most obvious one!")
  33.             else:
  34.                 print("YAY!")
  35.                 print("*happines noise*")
  36.                 print("I guessed your number!")
  37.         else:
  38.             print(f"You are just messing with me. I didn't say you could say \"{prompt}\"")
  39.             print("Since you don't play by rules, I quit.")
  40.  
  41.  
  42. def run_game():
  43.     print("Here we start then.")
  44.     print("-"*35)
  45.     guess(rng)
  46.    
  47.  
  48. def main():
  49.     print("Welcome to the game, where I guess the number you think of")
  50.     print("You should think of a number in range [0, 100]")
  51.     print("When I guess lower than your number, you should say low")
  52.     print("When I guess higher than your number, you should say high")
  53.     print("When I guess your number correctly, you should say correct")
  54.     print("If you lie, I'll know.")
  55.     print("Are we ready to start?", end=" ")
  56.     while True:
  57.         answer = input("Y/N\n").upper()
  58.         if answer == "N":
  59.             print("Oh okay then. Maybe another time.")
  60.             s(5)
  61.             print("Has your mind changed yet?")
  62.         elif answer == "Y":
  63.             run_game()
  64.             break
  65.         else:
  66.             print("You didn't enter a valid choice. I'm asking again now. Are we ready?")
  67.     input()
  68.  
  69. if __name__ == "__main__":
  70.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement