+ 1
Why doesn't this work?
a = 1 b = 2 x = a - b if a < b: print('a is less than b by x') else: print(a is greater than b by x')
2 Answers
+ 2
First, you forgot a ' in the second print.
Second, you only print strings.
If you want to print the variable values, you need to format it.
For example like this:
print(f'{a} is less than {b} by {x}')
also better use the absolute value
x = abs(a-b)
otherwise x can also be negative in the first case
"1 is less than 2 by -1" is not right
"1 is less than 2 by 1" is correct
+ 2
thank you