Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, Please can you help me with corrections. I have screenshots of the two-part question and my code with the line numbers. Can you see

Hello, Please can you help me with corrections.

I have screenshots of the two-part question and my code with the line numbers.

Can you see my improvement reccomendation below and tell me at which line to add this input and how to write the code in

so that it outputs as per below requirement.

NB **** I need you to use my code and rewrite it with the final code that includes what the "improvement recomendation" asks for ***

You Must use / work with My code that I already have ***

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Aspects of the submission that could be improved Please take note that the user should add the name of the txt file as an input and print out all of the equations together with the results. Use defensive coding to ensure that the program does not crash if the file does not exist and that the user is prompted again to enter the name of the file. - Create a simple calculator application that asks a user to enter two numbers and the operation (e.g. +,,x, etc.) that they'd like to perform on the numbers. Display the answer to the equation. Every equation entered by the user should be written to a text file. Use defensive programming to write this program in a manner that is robust and handles unexpected events and user inputs. Now extend your program to give the user the option to either enter two numbers and an operator, like before or to read all of the equations from a new txt file (the user should add the name of the txt file as an input) and print out all of the equations together with the results. Use defensive coding to ensure that the program does not crash if the file does not exist and that the user is prompted again to enter the name of the file. \#if else statement to print the answer for the given operator. \# Function to divide two numbers. \# If a number is divided by zero it will give the 'Division by Zero' message. def divide(x,y) : \( \mid \begin{array}{l}\text { try: } \\ \text { except ZeroDivisionError: } \\ \mid \text { return "Division by zero " }\end{array} \) \# Create a file in append and read mode. file = open("output.txt", "a+") while True: \( \mid \begin{array}{l}\text { \# Read numbers and operator } \\ \text { num1 = float(input("Enter first number: ")) } \\ \text { num2 = float(input("Enter second number: ")) } \\ \text { operator = input("Enter operator: ") } \\ \text { file.write(str(num1)+" "+operator+" "+str(num2)+" ") }\end{array} \) \# If else statement to print the answer for the given operator. if operator in (+,,m,,,) : if operator == ' + ' : print(add(num1, num2), " ") elif operator == ' ': | print(subtract(num1, num2), " ") elif operator == ': | print(multiply(num1, num2), " ") elif operator ==/ ': print(divide(num1, num2), " ) \# Option to continue or not. choice=input("ContinueY/NoN:"")ifchoice=="N":else

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Accounting And Auditing Research And Databases Practitioner's Desk Reference

Authors: Thomas R. Weirich, Natalie Tatiana Churyk, Thomas C. Pearson

1st Edition

1118334426, 978-1118334423

More Books

Students also viewed these Databases questions

Question

Know how to conduct a position analysis

Answered: 1 week ago

Question

Understand the roles of signs, symbols, and artifacts.

Answered: 1 week ago

Question

Know the three main dimensions of the service environment.

Answered: 1 week ago