Reputation:
I'm having trouble implementing a function into this program. The program I have currently works fine on its own without the function but I still need to find a way to put def finance(income, salesPrice):
into it. I also need to invoke the function with this: print(finance(income, salesPrice))
. I tried different ways but whenever I try to invoke the function, it says that income
is not defined.
This is what I have to make:
The function will test whether a person is qualified to finance an expensive car. They are qualified if their annual income is greater than $100,000 and the sales price is less than $1,000,000. The function returns a message to the program stating whether the person is qualified or not. The program invokes the finance() function with this print statement: print (finance (income, salesPrice))
and the user input the income and sales price.
def finance(income,salesPrice):
income = float(input("Please enter annual income: "))
while (income <= 0):
income = float(input("Invalid input! Please enter positive value: "))
income += 1
salesPrice = float(input("Please enter sales price of car: "))
if (income>100000 and salesPrice<1000000):
print("You are qualified to purchase this car.")
else:
print("You are not qualified to purchase this car.")
result = print(finance(income,salesPrice))
Upvotes: 0
Views: 74
Reputation: 724
The problem is indentation + You need to return a variable. EDIT: I edited the code based on your problem
def finance(income, sales_price):
if income > 100000 and sales_price < 1000000:
return "You are qualified to purchase this car."
else:
return "You are not qualified to purchase this car."
salesPrice = float(input("Please enter sales price of car: "))
income = float(input("Please enter annual income: "))
while income <= 0:
income = float(input("Invalid input! Please enter positive value: "))
income += 1
print (finance (income, salesPrice))
Upvotes: 2