Practice: more functions

Tags
Multiple choice

What will the following output, if the user enters 2, 3, and 5?

  • # Input
  • laugh_rating1 = float(input('How funny was the first comedian? '))
  • laugh_rating2 = float(input('How funny was the second comedian? '))
  • laugh_rating3 = float(input('How funny was the third comedian? '))
  •  
  • # Processing
  • average = compute_average(laugh_rating1, laugh_rating2, laugh_rating3)
  •  
  • # Output
  • print('Average: '+ str(average))
  •  
  • def compute_average(value1, value2, value3):
  •     total = value1 + value2 + value3
  •     average = total/3
  •     return average
Saving
A

3

B

3.333333

C

4

D

Error

Not graded. So why do it?

Reflect

Write a docstring for this function.

  • def predict_bitcoin_price(today_price):
  •     five_years = today_price / 2
  •     ten_years = 0
  •     return today_price, five_years, ten_years
If you were logged in as a student, the lesson would pause here, and you'd be asked to type in a response. If you want to try that out, ask for an account on this site.
Ethan
Ethan

Here's what I have:

  • def predict_bitcoin_price(today_price):
  •     '''
  •     Predict bitcoin prices over time.
  •  
  •     Parameters
  •     ----------
  •     today_price : float|int
  •         Price today.
  •  
  •     Returns
  •     -------
  •     today_price : float|int
  •         Price today.
  •     five_years : float|int
  •         Price in five years.
  •     ten_years : float|int
  •         Price in ten years.
  •     '''
  •     five_years = today_price / 2
  •     ten_years = 0
  •     return today_price, five_years, ten_years

Yay!