75.0k views
15 votes
Calculate the ERA

A pitcher’s ERA (earned runs average) is calculated by multiplying the number of runs (scores) times total innings in the game (usually 9) and then dividing by the total innings that the pitcher pitched.

Write a function that assumes that there were 9 innings in the game and takes in two numbers that represent the earned runs and the innings pitched. The function should return the ERA.

User Kevinskio
by
4.2k points

1 Answer

10 votes

Answer:

In Python:

def returnERA(runs,total):

ERA = runs *9/total

return ERA

Step-by-step explanation:

This defines the function. It receives the number of runs and the total runs as its parameters

def returnERA(runs,total):

This calculates the ERA

ERA = runs *9/total

This returns the ERA

return ERA

User Marcello Zago
by
4.3k points