AJP AJP - 5 months ago 8
Python Question

Basic Python Calculator

I am trying to learn Python and could do with a bit of help creating a basic savings calculator.

I have this so far but I am not sure where I am going wrong.

def savingsCalc(amount, number_of_weeks):
savings = (amount * number_of_weeks)
return savings
amount = float(input("Enter amount"))
number_of_weeks = float(input("Enter weeks"))
dollars, weeks = savingsCalc(amount, number_of_weeks)
print(str(dollars) + "dollars saved, amount of weeks" + str(weeks))

Answer

You didn't mention what problem you have faced. Try this. I guessed what you wanted to do. Firstly you didn't indent your code correctly. Secondly your savingsCalc is returning one value and you expecting two. I guessed you wanted to add the number_of_weeks at the end of printing.

def savingsCalc(amount, number_of_weeks):
    savings = (amount * number_of_weeks)
    return savings
amount = float(input("Enter amount"))
number_of_weeks = float(input("Enter weeks"))
dollars = savingsCalc(amount, number_of_weeks)
print(str(dollars) + "dollars saved, amount of weeks" + str(number_of_weeks))

Addition: In your next questions, add what problem you faced, what you did and also what you want the code to be.

Comments