Python Forum
Returning the highest value out of 3 values - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Returning the highest value out of 3 values (/thread-3079.html)



Returning the highest value out of 3 values - ComputerSkillet - Apr-27-2017

I'm trying to create a program that will allow the user to input 3 values and have the program state the highest value.
The error:

line 7, in <module>
    if num1>(num2,num3):
TypeError: '>' not supported between instances of 'int' and 'tuple'

print("This is a program that will return your largest value")

num1 = int(input("Please enter your first number: "))
num2 = int(input("Please enter your second number: "))
num3 = int(input("Please enter your third number: "))

if num1>(num2,num3):
    print("Your largest value is:", num1)

if num2 > (num1,num3):
    print("Your largest value is: ", num2)

else:
    print("Your largest value is: ", num3)



RE: Returning the highest value out of 3 values - wavic - Apr-27-2017

What you are trying is to check if an integer is greater than a tuple.
You need: max(num1, num2, num3)


RE: Returning the highest value out of 3 values - volcano63 - Apr-28-2017

If this is an assignment - which I suspect it is  -and you can't use max - as @wavic suggested - you can just do a simple step-by-step search
  1. Assign a new variable, e.g. the_greatest  Wink, to value of num1
  2. Compare num2 to the_greatest  , and if num2 is bigger - assign the_greatest to value of num2
  3. etc..
Just write it in Python Cool

PS This kind of operations are usually done on lists