Python Forum

Full Version: i need help with a small code
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
import random
l = 0
p = 3
o = 2
k = 1
x = input("enter a number 1, or 2: \t")

print("\n\n you chose " + x + " !")
  
if(x = k)
type(true)
x = random.randint(1.0, 10.0) 
print(x)


if x = 0
type(true)
x = random.randint(5.0, 8.0) 
print(x)

can someone please explain why this doesn't work?
A bare digit in your code is interpreted as a literal int. But input() always returns a str. Those can never be equal.

You need to either store and compare to strs, or you need to cast your input into an int or float. (via int() or float())