I'm struggling to code an if-statement series for an arbitrary and stupid game I designed called 'guessing game'. What should I add so that one loop compares the previous and the current answer and show it on console?
import random
listte = range(1, 21) # list contains 1-20
number = random.choice(listte) # computer generated number from the list
for i in range(3):
answer = int(input("What is your guess?"))
prevanswer = None # I came up with this but not really working?
if answer == number:
print "You got it!"
elif answer < number:
print "Nope, higher"
# this elif is not working with below codes
elif answer < number and answer > prevanswer:
print "still higher"
elif answer > number:
print "lower!"
prevanswer = i # also not working but this is what I came up with
An example execution scenario:
computer generated : 15
guess 1 : 17
prints "lower!"
guess 2: 10
print "make it higher"
guess 3: 12
print "still higher"