Reputation: 1
I'm trying to write a python program that will print me a random numbers array 1 thur 100, and also print out the max value of the array. This is what I have so far:
import random
import timeit
print [random.randint(0,100) for r in xrange(10)]
print "Max number in array is",
Upvotes: 0
Views: 267
Reputation: 1399
import random
rand_ar = [random.randint(1,100) for r in xrange(10)] # randint(0,100) includes 0 also.
print rand_ar
print "Max number in array is %i" % max(rand_ar)
Upvotes: 1
Reputation: 181077
You'll need to store the array as generated in a variable, and just use max
on it to get the maximum value;
import random
import timeit
my_array = [random.randint(0,100) for r in xrange(10)]
print my_array
print "Max number in array is", max(my_array)
Upvotes: 1