# This program calculates the average of the values # in a list. def main(): # Create a list. scores = [2.5, 8.3, 6.5, 4.0, 5.2] # Create a variable to use as an accumulator. total = 0.0 # Calculate the total of the list elements. for value in scores: total += value # Calculate the average of the elements. average = total / len(scores) # Display the total of the list elements. print ('The average of the elements is', average) # Call the main function. main()
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