I need to genereate a random number between 1 and 9, both included and then ask the user to guess the number, and tell them whether they guessed too low, too high or right.
I checked many different answers and I just can't spot the error, but apparently, it gets stuck in the line of code just after the while statement and won't read the "if"s. I'm using Python 2.7.13. So here's the code:
import random
list1 = range(1, 10)
times = 0
numcpu = random.choice(list1)
running = True
while running:
numhum = raw_input("Try to guess the random number between 1 and 9 the CPU generated: ")
if numhum in list1:
if numhum == numcpu:
print ("You got it mate! It only took you " + times + " times")
break
else:
print("Try again")
continuar = str(input("Continue (y/n)?"))
if continuar == "y":
times = times + 1
elif continuar == "n":
print "Ciao"
else:
print "Don't mess around with me, human"
elif numhum == "exit":
print("Ciao")
running = False
else:
"Don't mess around with me, human"