Engineering

Computer EngineeringQ&A LibraryCalculator 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 = 6Question

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

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:**

Step 2

**Screenshot of code #2:**

Step 3

**Screenshot of console outp...**

Tagged in

Find answers to questions asked by student like you

Show more Q&A

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 ...

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...

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...

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...

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...

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 ...

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...

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...

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...