232k views
1 vote
Project Stem 7.5 Code Practice.

Use the function written in the last lesson to calculate the gold medalists’ average award money for all of their gold medals. Define another function in your program to calculate the average.

Your program should then output the average award money, including the decimal place. Your program should use a total of two functions. You may assume that the user will provide valid inputs.

Sample Run
Enter Gold Medals Won: 3
How many dollars were you sponsored in total?: 20000
Your prize money is: 245000
Your average award money per gold medal was 81666.6666667

Previous Code:
def Get_Winnings(medals, sponsorship):


try:

medals = int(medals)

sponsorship = int(sponsorship)

except ValueError:


return "Your prize money is: Invalid"


prize_money = medals * 75000 + sponsorship


return f'Your prize money is: {prize_money:}'


medals = input("Enter Gold Medals Won: ")


sponsorship = input("For how many dollars was your event sponsored?: ")


print(Get_Winnings(medals, sponsorship))

(I got a 60 with this so not the best Code but it works.)

1 Answer

1 vote

Here try this

```

def Get_Winnings(medals, sponsorship):

prize_money = medals * 75000

total_winnings = prize_money + sponsorship

return total_winnings

def Calculate_Average(total_winnings, medals):

average = total_winnings/medals

return average

medals = int(input("Enter Gold Medals Won: "))

sponsorship = int(input("How many dollars were you sponsored in total?: "))

total_winnings = Get_Winnings(medals, sponsorship)

print("Your prize money is:", total_winnings)

print("Your average award money per gold medal was:", Calculate_Average(total_winnings, medals))

```

In this updated program, we added a new function called `Calculate_Average` which takes two arguments, `total_winnings` and `medals`, and returns the average award money per gold medal.

After getting the input from the user for the number of gold medals and sponsorship, we call the `Get_Winnings` function to calculate the total winnings. We then call the `Calculate_Average` function to calculate the average award money per gold medal and print it out.

Sample Output:

```

Enter Gold Medals Won: 3

How many dollars were you sponsored in total?: 20000

Your prize money is: 245000

Your average award money per gold medal was: 81666.66666666667

```

User Yue Harriet Huang
by
8.8k points