Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

trying to make a budget calculator but im lost

I have an assignment with the following request:

The program asks the student the max budget he has for the month. Then the program asks the student for the expenses he/she had on the first day of the month (On the screen it would say: What were your expenses on day #1?) And so on and so forth it keeps asking for the expenses of each of the following days. The program stops when one of two conditions occurs: when the accumulated expenses of the days that have been entered exceed the budget limit, in that case the program displays a message indicating that the budget has been met; or, in the second case, when the 30th day is reached and the corresponding expense has been entered, in that case if there is money left over from the budget the program must tell you how much is left over.

im trying to figure if using if fucntion some cycles and an input option to save the money spent in a day in that variable and also assign the max budget to recall a stop when the code finds im over budget in one of the 30 inputs and show wich day i went over budget

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

this is what i currently have i want to know what im doing wrong and in what i can improvise

Max = 240

print(
    "Lets keep on track your expences :)" + "\n"
)

Spent = int(input("input todays expenses:"))

if(Spent < Max):
    int(input("type the money you will spend the next days"))
elif(Spent> Max):
    print("you went overbudget you can't spend more, sorry! :(")

Thanks!

>Solution :

There are many ways to do it. You can try this:

max = 240
day = 1

while True:
    daySpent = input("What were your expenses on day #{} : ".format(day))
    
    max -= int(daySpent)
    
    day += 1
    
    if max <= 0:
        print("exceed the budget limit")
        break
    elif day > 30:
        print("Leftover: ", max)
        break

You can simply achieve it using a while loop to iterate each day and using if condition to break out the loop when conditions are met.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading