Write a program that asks the user for a number and an operation, then continue
ID: 3759108 • 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 13Explanation / 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
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.