-6

I need Python to analyze a long list of numbers stored in variables and pick the highest one. I need it to tell me which variable is the highest.

This is what I think I need (it's not actual code):

variable1 = 1000 variable2 = 242 variable3 = 87509 highest_number = pick_highest(variable1, variable2 ,variable3 ) print(highest_number) 

Output:

"variable3" 
3
  • 2
    I found about 160,000,000 results. Are you sure you found none? Commented Oct 18, 2021 at 22:08
  • 2
    Sort them, grab the last one, done. Don't try to overcomplicate extremely straightforward tasks. Commented Oct 18, 2021 at 22:10
  • Duplicate of stackoverflow.com/q/2474015 Commented Jan 10 at 18:47

1 Answer 1

1

Use the max() Function to Find Max Value in a List in Python.

Python has a pre-defined function called max() that returns the maximum value in a list.

Finding the maximum value using max() will only need a single line.

numbers = [55, 4, 92, 1, 104, 64, 73, 99, 20] max_value = max(numbers) print('Maximum value:', max_value) Output: Maximum value: 104

Sign up to request clarification or add additional context in comments.

2 Comments

If the list is a set of variables (containing numbers) will it tell me which variable had the highest number?
1. Google the Pearson correlation coefficient. (a measure of the linear association between two variables) 2. Use Numpy's corrcoef() function: np.corrcoef(var1, var 2)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.