I'm trying to create code that checks a number's truthiness.
print('run if true")
if 1 :
print ('run if true')
#output: run if true
... I want to create a program to check this and there is lot's of errors, please help!!!
@JerryTheMouse A bit late, but why not just do:
print(bool(float(input("Enter number you want to check: "))))
input() gets the number as a string
float() turns the string into a float (if the number isn't a float it'll just crash)
bool() checks its truthiness
print() prints the output
"0.0" evaluate to
false in js lol)
There are a few problems: firstly, when you use
input(), the result is a string, so before you process
i, you should do
j = int(i) and use
j instead. Next, you don't use
is to check for conditions: in this case, you can simply do
if j: run_this_code() else: run_that_code()
There are only a few things in python which evaluate to False, these include:
Everything else is True.
I hope you found this comment helpful
Upvote for vee freebucks!