#This is the hard coded array that the program will use. We assign the array to variable a. a = [2, 4, 3, 10, 33] #We will now add up all the numbers in the array and divide by the amount of numbers that are in the array and assign to variable b. b = sum(a)/len(a) #We print the average number of the array. print ("The average of the array is: %s" % b) #We now find what number is 20% more than the average in the array and assign to variable c. c = (b*.20) + b #We print this number. print ("The average of the array plus 20 percent is: %s" % c) #We create an empty array and call it y. This array will be used to hold all numbers greater than c. y = [] #Loop trhough array a and assign to variable x. for x in a: #If x is greater than c. if x > c: #If the above is true, add to the array y. y.append(x) #Print the numbers that are in array y. print ("The numbers in the array greater than the average plus 20 percent are: %s" % y)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question