Python Forum
i need help with a small code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
i need help with a small code
#1
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?
Larz60+ write Sep-22-2021, 08:47 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use bbcode tags on future posts.
Reply
#2
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())
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  small code for sampel asn1ate borys 0 857 Jul-26-2022, 10:48 AM
Last Post: borys
  Can someone explain this small snippet of code like I am a 5 year old? PythonNPC 3 1,230 Apr-08-2022, 05:54 PM
Last Post: deanhystad
  Quick Help - Timers - Need Small Solution for Working Code EwH006 5 4,025 Nov-17-2020, 04:09 AM
Last Post: EwH006
  this small code dosento work juanb007 2 2,687 Dec-18-2017, 01:15 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020