Python Forum
Returning the highest value out of 3 values
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Returning the highest value out of 3 values
#1
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)
Reply
#2
What you are trying is to check if an integer is greater than a tuple.
You need: max(num1, num2, num3)
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
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
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Methods that return the highest score from the list erfanakbari1 7 7,055 Mar-26-2019, 08:32 PM
Last Post: aankrose
  how to get the highest monthly average temperature? nikhilkumar 2 6,949 Jul-25-2017, 02:33 PM
Last Post: DeaD_EyE
  Numerically determining the highest a ball travels when shot straight up JakeWitten 3 3,382 Apr-22-2017, 04:37 PM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020