Created
April 11, 2014 11:33
-
-
Save pfeilbr/10460545 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def main(): | |
# create array of 500 elements | |
nums=[0]*500 | |
# populate each array element with a random int from 0-100 | |
for i in range(len(nums)): | |
nums[i]=random.randint(0, 100) | |
total=getTotal(nums) | |
avg=total/len(nums) | |
mini=getMin(nums) | |
maxi=getMax(nums) | |
print("Array total: ",total) | |
print("Array average: ",avg) | |
print("Lowest number found: ",mini) # I tried putting (min(i))) and (max(i))) but that didn't work either | |
print("Highest number found: ",maxi) | |
def getTotal(nums): | |
total=0 | |
for i in nums: | |
total+=i | |
return total | |
def getMax(nums): | |
maximum=nums[0] | |
# i is the value of each element in nums | |
for i in nums: | |
if(i>maximum): | |
maximum=i | |
return maximum | |
def getMin(nums): | |
minimum=nums[0] | |
# i is the value of each element in nums | |
for i in nums: | |
if(i<minimum): | |
minimum=i | |
return minimum | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment