Something Something - 2 months ago 4
Python Question

From a guessing game in python, I can't get myself to get the correct one

This is my code:

from sys import exit
import random
number = random.randint(1, 10)
count = 0

def guess():

print ("Input a number 1 - 10")
guess = input()

if guess == "I give up":
print ("The correct number was", number,"!")
print ("You tried", count, "times before giving up!")
if guess == (number):
print ("CORRECT!")
print (count, "failed attempts.")
print ("WRONG!")
print ("Try again!")
global count
count += 1

while True:

If I run this, I can keep guessing but never get the correct number. I said I gave up, and it gave me the correct number. But I already guessed that number, so I don't know what's the problem.


You are taking the input as a string rather than an integer. Thus, you may be comparing "5" to 5, which is false. Instead, call if int(guess) == (number)