Aug-07-2017, 10:38 AM
Hi, I am very new to python and programming, and I have to create an artificial intelligence that will try to guess a number that the user thinks of. I will reply with either higher or lower to tell it what to guess next. There also needs to be a way for it to check if the user's statements are contradicting themselves.
I have attempted it and gotten close. (Python 3.6.0 Btw)
I have attempted it and gotten close. (Python 3.6.0 Btw)
from random import randint again = 1 while int(again) == 1: print("Think of a number between 1 and 5 for the computer to guess") guess = (randint(1,5)) win = 0 low = 1 high = 5 while (win < 1): print("The computer guessed " + str(guess)) response = input("Is your number higher, lower or was that correct? (Put 1 for higher, 2 for lower and 3 for correct) ") print(" ") guess = int(guess) response = int(response) if low > high: win = win + 1 again = input("You either cheated, or were incorrect with your clues. Do you want to play again? (1 for yes, 0 for no) ") else: guess = (randint(low ,high)) if response == 1: low = int(guess) + 1 elif response == 2: high = int(guess) - 1 else: win = win + 1 again = input("It guessed it! Do you want to play again? (1 for yes, 0 for no) ")It doesn't use the "higher, lower" clues and incorectly says that the statements contradict.