Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from time import sleep as s
- rng = [0, 100]
- def guess(r):
- mid = sum(r) // 2
- prompt = input(f"I think your number is {mid}. ").lower()
- while " " in prompt:
- prompt = prompt.replace(" ", "")
- if r[0] == mid - 1 and r[1] == mid + 1 and (prompt == "high" or prompt == "low"):
- print("I concluded that you are a liar")
- print(f"There is only one number between {r[0]} and {r[1]}")
- print("I don't want to continue this game")
- elif (r[0] == mid or r[1] == mid) and (prompt == "high" or prompt == "low"):
- print("I concluded that you are a liar")
- print(f"There are no numbers between {r[0]} and {r[1]}")
- print("I don't want to continue this game")
- else:
- if prompt == "low":
- r[0] = mid
- print("Okay then. I'll try something higher")
- guess(r)
- elif prompt == "high":
- r[1] = mid
- print("Okay then. I'll try something lower")
- guess(r)
- elif prompt == "correct":
- if mid == 50:
- print("You gotta be kidding me! Nobody thinks of 50!")
- print("It's the most obvious one!")
- else:
- print("YAY!")
- print("*happines noise*")
- print("I guessed your number!")
- else:
- print(f"You are just messing with me. I didn't say you could say \"{prompt}\"")
- print("Since you don't play by rules, I quit.")
- def run_game():
- print("Here we start then.")
- print("-"*35)
- guess(rng)
- def main():
- print("Welcome to the game, where I guess the number you think of")
- print("You should think of a number in range [0, 100]")
- print("When I guess lower than your number, you should say low")
- print("When I guess higher than your number, you should say high")
- print("When I guess your number correctly, you should say correct")
- print("If you lie, I'll know.")
- print("Are we ready to start?", end=" ")
- while True:
- answer = input("Y/N\n").upper()
- if answer == "N":
- print("Oh okay then. Maybe another time.")
- s(5)
- print("Has your mind changed yet?")
- elif answer == "Y":
- run_game()
- break
- else:
- print("You didn't enter a valid choice. I'm asking again now. Are we ready?")
- input()
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement