+ 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')

6th Sep 2018, 10:38 AM
samir lohani
samir lohani - avatar
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
6th Sep 2018, 11:15 AM
Matthias
Matthias - avatar
+ 2
thank you
6th Sep 2018, 11:52 AM
samir lohani
samir lohani - avatar