Hello i need help in this code, it is given in my book like this but i am getting error. I am a school student and a new programmer.
#Program to find the greatest of the three numbers entered by the user
num1 = input('Enter the first number\t:')
num2 = input('Enter the second number\t:')
num3 = input('Enter the third number\t:')
if int(num1) > int(num2):
if int(num1) > int(num3):
big = int(num1)
else:
big = int(num2)
else:
if int(num2) > int(num3)
big = int(num2)
else:
big = int(num3)
print(big)
>Solution :
A missing char and a wrong choice between num2 and num3 :
if int(num1) > int(num2):
if int(num1) > int(num3):
big = int(num1)
else:
big = int(num3) # should be num3
else:
if int(num2) > int(num3): # was missing the ':'
big = int(num2)
else:
big = int(num3)
Improve by converting to int once
num1 = int(input('Enter the first number\t:'))
num2 = int(input('Enter the second number\t:'))
num3 = int(input('Enter the third number\t:'))
If needed, condition can be shortened ifTrue if condition else ifFalse
if num1 > num2:
big = num1 if num1 > num3 else num3
else:
big = num2 if num2 > num3 else num3
# or
big = (num1 if num1 > num3 else num3) if num1 > num2 else (num2 if num2 > num3 else num3)