subject
Computers and Technology, 11.03.2021 21:30 zach099

Ill give 100 points to whoever gives me the CORRECT answer. I keep getting syntax errors when I do the "add:" part. Can someone walk me through this code? Part A One of the biggest benefits of writing code inside functions is that we can reuse the code. We simply call it whenever we need it! Let’s take a look at a calculator program that could be rewritten in a more reusable way with functions. Notice that two floats (decimal numbers, but they can also include integers) are inputted by the user, as an operation that the user would like to do. A series of if statements are used to determine what operation the user has chosen, and then, the answer is printed inside a formatted print statement. 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.") Your job is to rewrite the program using functions. We have already looked at a function that adds two numbers. Using that as a starting point, we could call the add function from within our program in this way: if operation == “add”: result = add(num1, num2) print(num1, "+", num2,"=",result) Now it’s your turn to do the following: Type all of the original code into a new file in REPL. it. Copy the add function from the unit and paste it at the top of your program. 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. Rewrite the main code so that your functions are called. Part B There are many different ways that a user could tell us that he or she would like to add two numbers in our calculator program. The user could type “add”, “Add”, “ADD”, or “+”, to name a few possibilities. Of cour

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 01:50
A.) generate scaffolding to create database for your application. develop all the entities identified in assignment #2. add any additional that may be identified later. b.) add data validation rules to the models that are appropriate for your application and data. c.) create links for each scaffold in the header section. part 2: application updates [30 points] a.) add two additional views to the "home" controller you created in assignment #1. b.) the two views should be named as “privacy" and "". c.) link the two newly created views in the footer section. hint: you would need to modify the “home" controller definition and create “privacy.html.erb" and “.html.erb" files in appropriate locations.
Answers: 3
question
Computers and Technology, 23.06.2019 08:00
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
question
Computers and Technology, 23.06.2019 08:30
Helen's credit card has an apr of 15.32% and a grace period of 17 days and helen pays her balance in the full every month. if her last billing cycle ended on september 26, 2009, and she made her payment on october 11, 2009, did she owe any interest on her last statement's balance?
Answers: 3
question
Computers and Technology, 23.06.2019 09:00
Which company provides a crowdsourcing platform for corporate research and development? a: mtruk b: wiki answers c: mediawiki d: innocentive
Answers: 2
You know the right answer?
Ill give 100 points to whoever gives me the CORRECT answer. I keep getting syntax errors when I do t...
Questions
question
Mathematics, 05.05.2020 20:03
question
Mathematics, 05.05.2020 20:03
question
History, 05.05.2020 20:03
question
Mathematics, 05.05.2020 20:03
question
Mathematics, 05.05.2020 20:03
question
Mathematics, 05.05.2020 20:03
Questions on the website: 13722367