Ask Question

Write a calculator program that keeps track of a subtotal like real calculators do. Start by asking the user for an initial number. Inside a loop, asks the user for a mathematical operation and a second number. Do the operation with the first number on the second number. Keep track of the result as a 'subtotal' to be used as the first number when going back to the top of the loop. When the user quits, print out the final result and quit the program. See output for an example for the behavior of the program. The operations should be at least

+2
Answers (1)
  1. 24 July, 12:44
    0
    num1 = float (input ("Enter the first number: "))

    while True:

    print ("Add, Subtract, Multiply, Divide, or Quit?")

    choice = input ("Your choice is: ")

    if choice = = "Quit":

    break

    num2 = float (input ("Enter the second number: "))

    if choice = = "Add":

    num1 + = + num2

    print ("The subtotal is: " + str (num1))

    elif choice = = "Subtract":

    num1 - = num2

    print ("The subtotal is: " + str (num1))

    elif choice = = "Multiply":

    num1 * = num2

    print ("The subtotal is: " + str (num1))

    elif choice = = "Divide":

    num1 / = num2

    print ("The subtotal is: " + str (num1))

    print ("The final result is: " + str (num1))

    Explanation:

    Ask the user for the first number

    Create a while loop that iterates until specified condition occurs inside the loop

    Ask the user for the operation or quitting

    If the user chooses quitting, stop the loop. Otherwise, get the second number, perform the operation and print the subtotal

    When the loop is done, the user enters Quit, print the final value result
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write a calculator program that keeps track of a subtotal like real calculators do. Start by asking the user for an initial number. Inside ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers