+ 1

Why is the output nothing? Im a beginner so please dont be hard on me

x = 41 if x > 42: print(str(x) + “ is greater than 42”) if x < 43: print(str(x) + “ is less than 42”) Please assume I indented correct. I am using python

18th Jun 2021, 10:50 PM
Zane Al-Hamwy
Zane Al-Hamwy - avatar
3 Answers
+ 5
41 is not greater than 42 . And since "if x<43" is inside "if x>42", it isn't executed as well. You can have "if x<43" with same amount of indentation as the above if and you might get the output you are looking for!
18th Jun 2021, 10:53 PM
Abhay
Abhay - avatar
0
to piggy back off of Abhay , your second if statement will only run if x is greater than 42. if you want the second if statement to run all the time, you will need to unindent the second if statement as well. it would look something like this: x=41 if x>42: print(f’{x} is greater than 42’) # this is a format string that allows you to insert variables within a string using curly brakets if x<42: print(f“{x} is less than 42”)
19th Jun 2021, 12:27 AM
you are smart. you are brave.
you are smart. you are brave. - avatar
0
And in addition to the answers before check your double quotes! this is a double quote: " and that have you used: “ ! Its not a right double quote. So you are running into error.
19th Jun 2021, 4:07 AM
Angela
Angela - avatar