Sep-22-2017, 12:27 AM
(Sep-21-2017, 11:50 AM)Sagar Wrote: 1.Define a function calculateExpense().
2.In that function, you have to input the monthly budget and store it in budget variable.
3.Input the monthly expense and store it in expense variable.
4.Calculate money left.
5.Print the calculated money left.
6.Ask user if he wants to calculate more and store the answer in more variable with its case lowered.
7.Check whether the answer is "y" or "yes". If it is then call the calculateExpense() function. This is called recursion.
8. If the answer is something else then return.
9. After that function definition, call the function calculateExpense()
You can always modify and scale up the code and add new features into it.
I am sure it will help.
def calculateExpense(): budget = float(input("Enter your monthly budget")) expense = float(input("Enter your monthly expense")) moneyleft = budget-expense print("Money left in your budget is: ", moneyleft) more = input("Want to do it more ?").lower() if(more == "yes" or more== "y"): calculateExpense() else: return calculateExpense()
Thank you for helping! Unfortunately, when I tested your code, I had some issues.
Error:Traceback (most recent call last):
File "C:\Users\Sami3_000\Documents\School\Intro to Program Logic and Design\Ch4Ex3.py", line 18, in <module>
calculateExpense()
File "C:\Users\Sami3_000\Documents\School\Intro to Program Logic and Design\Ch4Ex3.py", line 12, in calculateExpense
more = input("Want to do it more ?").lower()
File "<string>", line 1, in <module>
NameError: name 'y' is not defined
I've looked through to see if I can make sense of what it's talking about, but sadly I cannot. If you can help with this too, I'd really appreciate it.