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")
3 Respostas
+ 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")
+ 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}")
🙃
+ 3
And since the commas automatically insert spaces, you can remove the spaces before 'is' and after 'than' 🙂