Ask coding questions

← Back to all posts
keeps saying functions arent defined
james21215 (0)

import house
def main():
determine_house()
determine_phone()
determine_car()
def determine_house(repeat):
house_price=float(input('Enter the price of the house you were going to pay'))
num_beds=int(input('Enter the number of bedrooms'))
house=house.house(house_price,num_beds)
foo=house.get_average_price()
woo=house.get_bedrooms()
if foo==218000:
if woo==2:
return ' You are paying average price for your house '
elif woo==1:
return ' You are being overpriced for this house relative to bedrooms '
determine_house(repeat-1)
else:
return ' you are getting a good deal for your house '
elif foo>218000:
return ' You are paying too much for a house in general '
else:
return ' You are getting a good price for this house in genereal '
def determine_phone(repeat):
phone_price=float(input(' Enter the price of the phone you were going to pay '))
type_phone=input(' Enter the type of phone ')
phone=phone.house(phone_price,type_phone)
voo=phone.get_average_price()
coo=phone.get_type_of_phone()
if coo==' Android ':
if voo==254:
return ' you are paying average price '
elif voo>254:
return ' you are being overpriced '
determine_phone(repeat-1)
else:
return ' you are getting a good deal for this phone '
elif coo==' iphone ':
if voo==687:
return ' you are paying average price for this phone '
elif voo>687:
return ' you are being overpiced for this phone '
determine_phone(repeat-1)
else:
return ' you are getting a good deal for this phone '
else:
print('this type of phone is not supported by the engine')
def determine_car(repeat):
car_price=float(input(' Enter the price of the car you were going to pay '))
model=input('Enter the model of the car youre thinking of buying')
car=car.house(car_price,model)
boo=car.get_average_price()
loo=car.get_model()
if loo==' toyota camry ':
if boo==23947:
return ' you are paying average price for this car '
elif boo>23947:
return 'you are being overpriced for this car'
determine_car(repeat-1)
else:
return 'you are getting a good deal for this car'
elif loo==' Honda Accord ':
if boo==23720:
return ' you are paying average price for this car '
elif boo>23720:
return ' you are being overpiced for this car '
determine_car(repeat-1)
else:
return ' you are not getting a good deal for this house '
else:
return ' this model of car is not supported by the engine '

main()

Commentshotnewtop
theangryepicbanana (687)

You can't use functions before you define them

james21215 (0)

@theangryepicbanana so I should put the functions at the bottom

theangryepicbanana (687)

@james21215 you should actually put the code defining the functions outside, and above, the main function like

def determine_house():
    ...
def determine_phone():
    ...
def determine_car():
    ...
def main():
    determine_house()
    determine_phone()
    determine_car()
AllAwesome497 (81)

Btw, if u provide the link to the repl, if we click on it it will open a little window to it, which makes it more readable, and allows us to see the exact error,
and edit a forked version of it.

james21215 (0)

@AllAwesome497 actually I did this on idle because this incorporates class and oop. I was just looking around and someone told me replit was a good place to get this code checked out but here's the error I'm getting. line 4, in main
determine_house()
UnboundLocalError: local variable 'determine_house' referenced before assignment

AllAwesome497 (81)

@james21215 assuming that determine_house(), determine_phone(), and determine_car() are all in a file named home.py, change import Home to from Home import * or from home import determine_house(), determine_phone(), determine_car() or use home.<func> instead of just <func>. if u do the first option, remove anything that uses house. before it

james21215 (0)

@AllAwesome497 house.py is a series of classes I'm defining the functions in the test class.

AllAwesome497 (81)

@james21215 are
determine_house()
determine_phone()
determine_car()
defined in house.py

AllAwesome497 (81)

@james21215 ok then u need to define them. it has to be defined before it is used. you could put them in a seperate file (eg: funcs.py) and add from funcs import * and u could use that

EvanKrainik (7)

You are using undefined functions. put the def ____():s before calling them.