1Day2Die
1Day2Die

Reputation: 29

Python compare two or more integer values and print out the higher one incl. the variable name

this must be a simple problem but i just cant find the right solution.

So, i've got, lets say 4 variables.

number1 = 10
number2 = 14
number3 = 6
number4 = 11

What i need is for the Programm to take all variables, compare them, and print out the highest number including the variable name. E.G

"variable 'number4' has the highest number with a value of: '11'

There has been nothing helpful so far on the internet but i cant imagine it being that hard. Im probably missing out on a obvious function here or something

Upvotes: 0

Views: 2238

Answers (1)

Same as this other issue: How to get max() to return variable names instead of values in Python?

Basically it makes sense to convert your data structure to a dictionary instead of having individual variables.

Upvotes: 3

Related Questions