Calculator Challange Python CodingCreate a simple calculator that takes in TWO numbers from the user and then asks the user to select if they want to ADD, SUBTRACT, MULTIPLY or DIVIDE to get the answer.I have coded...print("input whole numbers please, no decimals")again=""while again!="N":first=int(input("What is the first number?"))last=int(input("What is the last number?"))#let user pick the operation, assign numbers to the operationsoperation=int(input("Would you like to 1) add, 2)subtract, 3)multiply, or 4) divide?"))if operation==1:answer=first+lastelif operation==2:answer=first-lastelif operation ==3:answer=first*lastelif operation == 4:answer=first/lastelse:print("You did something wrong, try again.")print("The answer: %s"%(answer))again=str(input("Would you like to go again? Y/N")).upper()same=str(input("Would you like to use the same two numbers? Y/N")).upper()while same=="Y":operation = int(input("Would you like to 1) add, 2)subtract, 3)multiply, or 4) divide?"))if operation == 1:answer = first + lastelif operation == 2:answer = first - lastelif operation == 3:answer = first * lastelif operation == 4:answer = first / lastelse:print("You did something wrong, try again.")print("The answer: %s" % (answer))again = str(input("Would you like to go again? Y/N")).upper()same = str(input("Would you like to use the same two numbers? Y/N")).upper()Finish the coding to...-the numbers inputted and the answers are written into a text file-output to the text file the full sentence of what operations you are doing.  For example output to the text file : 2 x 3 = 6

Question
Asked Dec 13, 2019
47 views

Calculator Challange 

Python Coding

Create a simple calculator that takes in TWO numbers from the user and then asks the user to select if they want to ADD, SUBTRACT, MULTIPLY or DIVIDE to get the answer.

I have coded...

print("input whole numbers please, no decimals")
again=""
while again!="N":
first=int(input("What is the first number?"))
last=int(input("What is the last number?"))
#let user pick the operation, assign numbers to the operations
operation=int(input("Would you like to 1) add, 2)subtract, 3)multiply, or 4) divide?"))
if operation==1:
answer=first+last
elif operation==2:
answer=first-last
elif operation ==3:
answer=first*last
elif operation == 4:
answer=first/last
else:
print("You did something wrong, try again.")
print("The answer: %s"%(answer))
again=str(input("Would you like to go again? Y/N")).upper()
same=str(input("Would you like to use the same two numbers? Y/N")).upper()
while same=="Y":
operation = int(input("Would you like to 1) add, 2)subtract, 3)multiply, or 4) divide?"))
if operation == 1:
answer = first + last
elif operation == 2:
answer = first - last
elif operation == 3:
answer = first * last
elif operation == 4:
answer = first / last
else:
print("You did something wrong, try again.")
print("The answer: %s" % (answer))
again = str(input("Would you like to go again? Y/N")).upper()
same = str(input("Would you like to use the same two numbers? Y/N")).upper()

Finish the coding to...

-the numbers inputted and the answers are written into a text file

-output to the text file the full sentence of what operations you are doing.  For example output to the text file :

 
2 x 3 = 6
check_circle

Expert Answer

Step 1

A Python program for the given criteria is as follows,

File name : “main.py”

print("Input whole numbers please, no decimals")

again=""

#input("Do you want to continue Y/N")

while again!="N":

    first=int(input("What is the first number?"))

    last=int(input("What is the last number?"))

    #let user pick the operation, assign numbers to the operations

    operation=int(input("Would you like to 1) add, 2)subtract, 3)multiply, or 4) divide?"))

    if operation==1:

        answer=first+last

        print(first,"+",last,"=", answer,file=open("output.txt", "a"))

    elif operation==2:

        answer=first-last

        print(first,"-",last,"=", answer,file=open("output.txt", "a"))

    elif operation ==3:

        answer=first*last

        print(first,"x",last,"=", answer,file=open("output.txt", "a"))

    elif operation == 4:

        answer=first/last

        print(first,"/",last,"=", answer,file=open("output.txt", "a"))

    else:

        print("You did something wrong, try again.")

    again=str(input("Would you like to go again? Y/N")).upper()

    same=str(input("Would you like to use the same two numbers? Y/N")).upper()

    while same=="Y":

        operation = int(input("Would you like to 1) add, 2)subtract, 3)multiply, or 4) divide?"))

        if operation == 1:

            answer = first + last

            print(first,"+",last,"=", answer,file=open("output.txt", "a"))

        elif operation == 2:

            answer = first - last

            print(first,"-",last,"=", answer,file=open("output.txt", "a"))

        elif operation == 3:

            answer = first * last

            print(first,"x",last,"=", answer,file=open("output.txt", "a"))

        elif operation == 4:

            answer = first / last

            print(first,"/",last,"=", answer,file=open("output.txt", "a"))

        else:

            print("You did something wrong, try again.")

        again = str(input("Would you like to go again? Y/N")).upper()

        same = str(input("Would you like to use the same two numbers? Y/N")).upper()

Screenshot of code #1:

help_outline

Image Transcriptionclose

print("Input whole numbers please, no decimals") again=" #input("Do you want to continue Y/N") while again!="N": first=int (input ("What is the first number?")) last=int (input ("What is the last number?")) #Let user pick the operation, assign numbers to the operations operation=int(input ("Would you like to 1) add, 2) subtract, 3)multiply, or 4) divide?")) if operation==1: answer-first+last print(first,"+",last, elif operation==2: ', answer, file=open("output.txt", "a")) answer first-last print(first," -",last,"=", answer, file=open("output.txt", "a")) elif operation ==3: answer first*last print(first,"x",last,"=" elif operation 4: ', answer, file=open ("output.txt", "a")) answer=first/last print(first,"/",last,"=", answer, file=open("output.txt", "a")) else: print ("You did something wrong, try again.") again=str(input ("Would you like to go again? Y/N")).upper() same=str(input ("Would you like to use the same two numbers? Y/N")).upper(()

fullscreen
Step 2

Screenshot of code #2:

help_outline

Image Transcriptionclose

while same=="Y" operation if operation == 1: answer = first + last print(first,"+",last,"=' elif operation == 2: int(input ("Would you like to 1) add, 2)subtract, 3)multiply, or 4) divide?")) answer, file=open("output.txt", "a")) answer = first - last print (first," -" elif operation == 3: answer, file=open("output.txt", "a")) ,last, answer = first * last print(first,"x",last,"=" elif operation == 4: answer, file=open ("output.txt", "a")) answer = first / last print(first,"/",last, else: answer, file=open("output.txt", "a")) print ("You did something wrong, try again.") again = str(input ("Would you like to go again? Y/N")).upper () same = str(input ("Would you like to use the same two numbers? Y/N")).upper ()

fullscreen
Step 3

Screenshot of console outp...

help_outline

Image Transcriptionclose

Input whole numbers please, no decimals What is the first number?1 What is the last number?2 Nould you like to 1) add, 2) subtract, 3)multiply, or 4) divide?1 Nould you like to go again? Y/Ny Nould you like to use the same two numbers? Y/Nn What is the first number?3 What is the last number?2 Nould you like to 1) add, 2) subtract, 3)multiply, or 4) divide?2 Nould you like to go again? Y/Ny Nould you like to use the same two numbers? Y/Ny Nould you like to 1) add, 2) subtract, 3)multiply, or 4) divide?3 Nould you like to go again? Y/Ny Nould you like to use the same two numbers? Y/Ny Nould you like to 1) add, 2) subtract, 3) multiply, or 4) divide?4 Nould you like to go again? Y/Ny Nould you like to use the same two numbers? Y/Ny Nould you like to 1) add, 2) subtract, 3)multiply, or 4) divide?5 You did something wrong, try again. Nould you like to go again? Y/Nn Nould you like to use the same two numbers? Y/Nn ..Program finished with exit code 0 Press ENTER to exit console.

fullscreen

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Engineering

Related Computer Engineering Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: Selling a new vehicle pays a salesperson $1500. Selling a used vehicle pays a commission of 5% of th...

A: In the given question, programming language is not mentioned to write the code.So, I choose java to ...

question_answer

Q: Write a program in Eclipse called LoopMethod (main method) that contains a method called printNums (...

A:  Algorithm: Step 1: Import required package.Step 2: Define “LoopMethod” class.Step 3: Define main fu...

question_answer

Q: Do you think technologies like Big Data and Predictive Analytics in Marketing would have worked 10-1...

A: The technologies like Big Data would not have worked 10-15 years back as due to lack of large datase...

question_answer

Q: What could be the value of the register Stl after executing the instruction SLL $t1, $t0, 1 if the v...

A: A Shift left logical (SLL) of one position moves each bit to the left by one.After executing the giv...

question_answer

Q: Identify the errors in the following program. 2 errorspublic class Test {public static void main(St...

A: The two errors in the given program are:The argument is passed in wrong order in the line nPrintln(5...

question_answer

Q: Suppose we have a computer with the following characteristics: the magnetic disk has an accesslatenc...

A: In this problem the computer has a following characteristic:The access latency of magnetic disk has ...

question_answer

Q: Hello, I am trying to write a program: Write a .py file like MainFiles.py In that .py, create a func...

A: A python file is created named as MainFiles.py:Def main( ):Print(“ Welcome to python”)The above pyth...

question_answer

Q: Don't really know how to start solving this problem.

A: Using 4 bit counter we can implement a modulo 12 synchronous counter by ensuring that all the flip f...

question_answer

Q: How would i solve this in python i cant figure it out A wall has been built with two pieces of sheet...

A: Program plan:Initialize the length of the small sheetrock in the variable “small”.Initialize the len...