0

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

1Day2Die
  • 29
  • 9
  • use `max()` to get the highest value. Finding the variable name seems impossible as also stated [here](https://stackoverflow.com/questions/18425225/getting-the-name-of-a-variable-as-a-string/18425523) and [here](https://stackoverflow.com/questions/544919/can-i-print-original-variables-name-in-python). – Banana Apr 30 '20 at 09:20
  • Ye but using max() would only return "4". I need it to remember the variable name aswell. Example: "variable w = 4 as the highest value" – 1Day2Die Apr 30 '20 at 09:21
  • 1
    Does this answer your question? [Getting the name of a variable as a string](https://stackoverflow.com/questions/18425225/getting-the-name-of-a-variable-as-a-string) – Bernardo stearns reisen Apr 30 '20 at 10:33

1 Answers1

3

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.