-1

Take three numbers from user, and print the biggest.

num1 = int(input(" Num1: "))
num2 = int(input(" Num2: "))
num3 = int(input(" Num3: "))

if num1 > num2 or num3:
    print(num1)

elif num2 > num1 or num3:
    print(num2)

else:
    print(num3)

Whatever I put, the terminal still shows input("num1")

Guy
  • 46,488
  • 10
  • 44
  • 88
Armin
  • 3
  • 3

6 Answers6

2

num1 > num2 or num3 means that either num1 > num2 or num3 shuld be truthy and if num3 if a number (other than 0) it is truthy. So 1st condition is always true

You should probably change it to num1 > num2 or num1 > num3.

Vulwsztyn
  • 2,140
  • 1
  • 12
  • 20
1
if num1 > num2 or num3:

Doing this, num3 will also have truth value.

Basically what the statement is doing

if (num1>num2) or num3:

Regardless of the fact that num2 is less or more or equal to num1, num3 will have truth value, making python execute the statement.

Change all the Statements to

if num1 > num2 or num1 > num3:
0

instead of if num1 > num2 or num3: you should use num1 > num2 or num1 > num3: because when you type if num1 > num2 or num3, it checks the condition then checks num3 is zero or not if it is not zero it returns true for your statement.

0

Currently, at @Vulwsztyn pointed out, you have an always true condition in your code. To get the soltion you want, you can use the inbuilt method max() to solve your question.

The code should look like:

num1 = int(input(" Num1: "))
num2 = int(input(" Num2: "))
num3 = int(input(" Num3: "))

print(max(num1, num2, num3))
veedata
  • 1,048
  • 1
  • 9
  • 15
0
*num1 = int(input(" Num1: "))
num2 = int(input(" Num2: "))
num3 = int(input(" Num3: "))

if num1 > num2 and num1 > num3:
    print(num1)

elif num2 > num1 and num2 > num3:
    print(num2)

else:
    print(num3)*

else:
    print(num3)

or checs if any of the condition passes. and checks for all conditions to pass

Irfan wani
  • 4,084
  • 2
  • 19
  • 34
0

You're not comparing numbers in the right way, you should use an "and" instead of "or" This is the working code:

num1 = int(input(" Num1: "))
num2 = int(input(" Num2: "))
num3 = int(input(" Num3: "))

if num1 > num2 and num1>num3:
    print(num1)

elif num2 > num1 and num2>num3:
    print(num2)

else:
    print(num3)

The short way for all this would be use the max function like max(num1, num2, num3)

s_frix
  • 323
  • 2
  • 11