0

Why does this code not work?

x=6 y=2 if x > y: print (x" is greater than "y) else: print(x" is not greater than "y) print("Program ended")

20th Feb 2019, 5:48 PM
David Wehar
David Wehar - avatar
3 Answers
+ 11
You've forgotten the commas inside the "print" function: x=6 y=2 if x > y: print (x," is greater than ",y) else: print(x," is not greater than ",y) print("Program ended")
20th Feb 2019, 5:54 PM
Maz
Maz - avatar
+ 7
If you want to be a real smartie, you can combine lines 3, 4, 5 and 6 into one line: print(f"{x} is{' ' if x > y else ' not '}greater than {y}") 🙃
22nd Feb 2019, 6:05 AM
David Ashton
David Ashton - avatar
+ 3
And since the commas automatically insert spaces, you can remove the spaces before 'is' and after 'than' 🙂
21st Feb 2019, 2:15 PM
David Ashton
David Ashton - avatar