Hi All 👋
I'm stuck with this coding. Any help would be appreciated
Heres the prompt
In the next code cell, create a function get_expected_cost() that has two arguments:
- beds - number of bedrooms
- baths - number of bathrooms
It should return the expected cost of a house with that number of bedrooms and bathrooms. Assume that:
- the expected cost for a house with 0 bedrooms and 0 bathrooms is 80000.
- each bedroom adds 30000 to the expected cost
- each bathroom adds 10000 to the expected cost.
For instance,
- a house with 1 bedroom and 1 bathroom has an expected cost of 120000, and
- a house with 2 bedrooms and 1 bathroom has an expected cost of 150000.
Here is my coding. What am I doing wrong?
# This function calculates the expected cost of a house
# based on the number of bedrooms and bathrooms.
# Base cost = 80000
# Each bedroom adds 30000
# Each bathroom adds 10000
def get_expected_cost(beds, baths):
value = 80000 + (beds * 30000) + (baths * 10000)
return value
# Try to check with q1 (if you're in a course platform), or run manual tests
try:
q1.check(get_expected_cost)
except NameError:
# q1 is not defined, so we'll test the function ourselves
print("q1 not defined – running manual tests instead:")
print("1 bed, 1 bath:", get_expected_cost(1, 1)) # Expected: 120000
print("2 bed, 1 bath:", get_expected_cost(2, 1)) # Expected: 150000
print("0 bed, 0 bath:", get_expected_cost(0, 0)) # Expected: 80000