Computers and Technology
Computers and Technology, 02.04.2020 07:27, 860jay

1. Type all of the original code into a new file in REPL. it. 2. Copy the add function from the unit and paste it at the top of your program. 3. Write 3 additional functions: subtract, multiply, and divide. Pay careful attention to the parameters and return statement. Remember to put the three functions at the top of your Python program before your main code. 4. Rewrite the main code so that your functions are called.

that “add” is the same as “Add”.
We can use a list to make our program a bit more robust. We can also use the IN operator to check for certain values in that list. Take a look at this if statement’s opening line:
if operation in [“add”, “Add”, “ADD”, “+”]:
1. Make those changes in your program and verify that it works.
2. Consider all of the possible words the user might enter to subtract, multiply, or divide.
3. Rewrite the first lines of each of your if statements to use lists.
4. Thoroughly test your new program, trying out each of the four operations.
5. Share the link to your Python code in REPL. it with your teacher by clicking on the share button and copying the link.

The code is

num1 = float(input("Enter your first number: "))
num2 = float(input("Enter your second number: "))
operation = input("What operation would you like to do? Type add, subtract, multiply, or divide.")
if operation == "add":
print(num1, "+", num2,"=", num1 + num2)
elif operation == "subtract":
print(num1, "-", num2,"=", num1 - num2)
elif operation == "multiply":
print(num1, "*", num2,"=", num1 * num2)
elif operation == "divide":
print(num1, "/", num2,"=", num1 / num2)
else:
print("Not a valid operation.")

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 08:00, ionmjnm3041
The managing director of a company sends a christmas greeting to all his employees through the company email. which type of network does he use? he uses an .
Answers: 3
image
Computers and Technology, 23.06.2019 18:40, brooklyn4932
How does is make you feel when you're kind to others? what are some opportunities in your life to be more kind to your friends and loved ones? imagine a world where kindness has be outlawed. how would people act differently? would your day-to-day life change significantly? why or why not?
Answers: 2
image
Computers and Technology, 24.06.2019 08:20, brinks7994
Which type of entity describes a fundamental business aspect of a database? a. linking b. lookup c. domain d. weak
Answers: 3
image
Computers and Technology, 24.06.2019 12:50, vianca15
What percentage of teens plays video games? a.97% b.100% c.74% d.50%
Answers: 1
Do you know the correct answer?
1. Type all of the original code into a new file in REPL. it. 2. Copy the add function from the unit...

Questions in other subjects:

Konu
Mathematics, 28.08.2019 07:10