'Guess the Number game isn't working as intented [duplicate]

Random Number Generator - Guess It

Did a much more complex variant of this. (250+ lines) But when I tested it, even if I guessed the number correctly(it was between 1-20) it didn't accept it. Every stage, I programmed the computer to tell me a statement about the number, using if, elif and else commands. When I guessed the number, it just said the number is incorrect and told me a new statement about number. Could someone help, please? In this mini variant as well, if I get the correct answer, it still responds to the if statement.

import random 

list = [1,2,3]
target = print(random.choice(list))

guess = input("What is the target number?")
if guess == target :
   print("Well done.")
else:
    print("The number you have guessed isn't correct.")


Solution 1:[1]

You need to convert the guess into an integer before comparison. and remove the print statement from the variable definition. You also need to rename the list variable as it is a protected name.

import random 

listNumbers = [1,2,3]
target = random.choice(listNumbers)

guess = int(input("What is the target number?"))
if guess == target :
   print("Well done.")
else:
    print("The number you have guessed isn't correct.")

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1