167k views
3 votes
Python problem:

Write a program in which the program guesses the number that the user is thinking about. Example of

output per screen:

Think of a number from 1 to 4.

Answer S (yes) or N (no) to my questions.

Is the number thought to be greater than 2? S

Is the number thought to be greater than 3? N

The number thought about is 3

See you next time!

User Gawkface
by
8.2k points

1 Answer

3 votes

print("Think of a number from 1 to 4")

print("Answer S (yes) or N (no) to my questions.")

choice = input("Is the number thought to be greater than 2? ")

if choice == "S":

choice = input("Is the number thought to be greater than 3? ")

if choice == "S":

print("The number thought about is 4")

elif choice == "N":

print("The number thought about is 3")

elif choice == "N":

choice = input("Is the number thought to be greater than 1? ")

if choice == "S":

print("The number thought about is 2")

elif choice == "N":

print("The number thought about is 1")

print("See you next time!")

This works for me. Best of luck!

User Wonde
by
7.3k points