Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that asks the user for a number and an operation, then continue

ID: 3762603 • Letter: W

Question

Write a program that asks the user for a number and an operation, then continue to ask for more numbers and operators until an equals sign is entered. Below is a flow chart detailing how the program should operate, and following that is an example of a run case: What is the first number? 5 5, Enter an operation: + What is the next number? 3 8, Enter an operation: -What is the next number? 2 6, Enter an operation: / What is the next number? 3 3,Enter an operation: + What is the next number? 10 13, Enter an operation: = The final result is 13

Explanation / Answer

n = int(input("What is the first number? ")) while(1): op = input(str(n)+", Enter an operation: ") if(op=='='): print("The final result is "+str(n)) break m = int(input("What is the next number? ")) if(op=='+'): n += m elif(op=='-'): n -= m elif(op=='*'): n *= m elif(op=='/'): n /= m

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote