i need help with a small code - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: i need help with a small code (/thread-34986.html) |
i need help with a small code - Jacobthefirst - Sep-22-2021 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? RE: i need help with a small code - bowlofred - Sep-22-2021 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() )
|