hello to new to coding im coding in python and i run into a problom can someone th=ake a look?
import random
import time
number = random.randint(1,9)
print("hello new user")
print("what is your name?")
name = input()
print("hello",name)
print("guass a number bitween 1 to 9")
print(number)
number1 = input()
if number == number1:
print('Correct')
the part at the end to check if the numbers at the end are Equal isnt working as expected
CodePudding user response:
User input is always a string
so you need to convert it to int
.
import random
import time
number = random.randint(1,9)
print("hello new user")
print("what is your name?")
name = input()
print("hello",name)
print("guass a number bitween 1 to 9")
print(number)
# Convert input to int
number1 = int(input())
if number == number1:
print('Correct')
CodePudding user response:
Remember that input
returns a string. The string "1
" is not equal to the integer 1
.
You need to convert the string that input
returns to an int, using the int
function:
some_numeric_input = input()
an_integer = int(some_numeric_input)