Question

In: Computer Science

Write a program in PYTHON, using a while loop, that asks the user to enter the...

Write a program in PYTHON, using a while loop, that asks the user to enter the amount that they have budgeted for the month. The program should then prompt the user to enter their expenses for the month. The program should keep a running total. Once the user has finished entering their expenses the program should then display if the user is over or under budget.

The output should display the monthly budget, the total expenses and whether the user is over or under budget. Use a empty return (enter key) to end the loop.

Solutions

Expert Solution

#variable declaration and initialization
totalAmount = 0
totalExpense = 0

while True:
#get user input
amount = input("Enter the amount that they have budgeted for the month: ")
expense = input("Enter expense for the month: ")
if amount == '' and expense == '':
break
else:
  
totalAmount = totalAmount + int(amount)
totalExpense = totalExpense + int(expense)

#calcualte budget
budget = totalAmount - totalExpense

#display result
print("\nMonthly budget =", budget)
print("Total expense = ", totalExpense)
if budget<0:
print("Over budget")
else:
print("Under budget")

The screenshot of the above source code is given below:

OUTPUT:

Enter the amount that they have budgeted for the month: 300
Enter expense for the month: 200
Enter the amount that they have budgeted for the month: 200
Enter expense for the month: 20
Enter the amount that they have budgeted for the month:
Enter expense for the month:

Monthly budget = 280
Total expense = 220
Under budget


  


Related Solutions

Using a while loop. Write a JAVA program that asks a user for an integer between...
Using a while loop. Write a JAVA program that asks a user for an integer between 1 and 9. Using the user input, print out the Fibonaccci series that contains that number of terms. Sample output: How many terms would like printed out for the Fibonacci Sequence? 7 Fibonacci Series of 7 numbers: 0 1 1 2 3 5 8
Design a Python program with a While loop that lets the user enter a number. The...
Design a Python program with a While loop that lets the user enter a number. The number should be multiplied by 10 and the result stored in a variable named "product". The loop should repeat as long as the product variable < 10. Anything not completely obvious to a newbie should be commented on as in line comments. Should be modulated and repeatable as well as there should be an invocation of the main routine at the end of the...
In Python write a program that asks the user to enter the monthly costs for the...
In Python write a program that asks the user to enter the monthly costs for the following expenses incurred from operating his or her automobile: loan payment, insurance, gas, oil, tires, and maintenance the program should then display the total monthly cost of these expenses, and the total annual cost of these expenses. your program MUST have BOTH a main function AND a function named calcExpenses to calculate the expenses. DO NOT display the expenses inside of the calcExpenses function!!...
Write a complete program using the do-while loop that prompts the user to enter a string...
Write a complete program using the do-while loop that prompts the user to enter a string and displays its first and last characters. Repeat until the user enter a string that contains only one character. Here is an example to show you how the output may look like: <output> Enter a string ( type only one character to exit): this is my string The first character is t The last character is g Enter a string ( type only one...
Using Python Write a program that does the following in order: 1.     Asks the user to enter...
Using Python Write a program that does the following in order: 1.     Asks the user to enter a name 2.     Asks the user to enter a number “gross income” 3.     Asks the user to enter a number “state tax rate” 4.     Calculates the “Federal Tax”, “FICA tax” and “State tax” 5.     Calculates the “estimated tax” and round the value to 2 decimal places 6.     Prints values for “name”, “gross income” and “estimated tax” The program should contain three additional variables to store the Federal tax, FICA...
Java program Use Do-while Write a do-wile loop that asks the user to enter two numbers....
Java program Use Do-while Write a do-wile loop that asks the user to enter two numbers. The numbers should be added and the sum displayed. The loop should ask the user whether he or she wishes to perform the operation again. If so, the loop should repeat, otherwise, it should terminate. Use Continue branching statement Write a program that reads an integer and display all the positive ODD numbers from 0 to n (integer entered by the user). Use CONTINUE...
​​​​​​​For java program. Write a while loop that will let the user enter a series of...
​​​​​​​For java program. Write a while loop that will let the user enter a series of integer values and compute the total values and number of values entered. An odd number will stop the loop. Display the number of iterations and the total of the values after the loop terminates. for Loop Write a for loop to display all numbers from 13 - 93 inclusive, ending in 3. Write a for loop to display a string entered by the user...
(IN PYTHON) Write a program that asks the user repeatedly to enter a student's score or...
(IN PYTHON) Write a program that asks the user repeatedly to enter a student's score or enter -1 to stop. When finished entering all the scores, the program should display the number of scores entered, the sum of the scores, the mean, the lowest and the highest score. (IN PYTHON)
Write a Python program that asks the user to enter the monthly costs for the following...
Write a Python program that asks the user to enter the monthly costs for the following expenses incurred from operating his or her automobile: Loan payment Insurance Gas Oil Tires Maintenance Write a function that takes these six items as arguments and computes the total cost of these expenses. Write a main program that asks the user for these six items and calls your function. Print total monthly cost and the total annual cost for these expenses. Your function should...
Please write in Python code please: Write a program that asks the user to enter 5...
Please write in Python code please: Write a program that asks the user to enter 5 test scores between 0 and 100. The program should display a letter grade for each score and the average test score. You will need to write the following functions, including main: calc_average – The function should accept a list of 5 test scores as an input argument, and return the average of the scores determine_grade – The function should accept a test score as...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT