jeudi 1 décembre 2016

Create List of 100 Random Integers, Return Max Value

Write a Python function that will take a the list of 100 random integers between 0 and 1000 and return the maximum value. (Note: there is a builtin function named max but pretend you cannot use it.)

Here's what I tried:

import random

list = []
for i in range(100):
    list.append(random.randint(0,1000))          

def max(list):

#sort list from least to greatest
    answer = list.sort()
#get last item in list (max value)
             list.pop()

    return max  


print (max(list))

As you can see, what I'm confused about is how to correctly use the sort and pop methods to return the max value within the max function. I'm currently getting:

ParseError: bad input on line 12

Which is this line:

list.pop()

Not sure how to correct this. Thanks.




Aucun commentaire:

Enregistrer un commentaire