Python Compare values stored in variables, then print the variable name


I have tried to use the max code but it printed out the largest number not the variable name.

textfile = open("Preference.txt","r")
for x in textfile:
    preferline = x.strip('\n').split(",")
    if preferline[0]=='1':
    elif preferline[1]=='1':
    elif preferline[2]=='1':


Is there a code to print out the variable with the highest values…


why would you want to print the variable name? The variable names are only for the internal working of the program, a end user using your program has no idea what the variables are, they are interested in the value.

as we can deduce from this question:

the only ways to accomplish this are difficult and are often best avoid


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.