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.

image text in transcribed

image 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

Oracle Database 10g Insider Solutions

Authors: Arun R. Kumar, John Kanagaraj, Richard Stroupe

1st Edition

0672327910, 978-0672327919

Students also viewed these Databases questions