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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 14:30, chaparro0512
Create a pseudocode design to prompt a student for their student id and the titles of the three classes they want to add. the solution should display the student’s id and a total bill. • bill a student using the following rules: o students can only add up to 3 classes at a time.
Answers: 3
image
Computers and Technology, 23.06.2019 19:40, Latoyajenjins1789
Use a physical stopwatch to record the length of time it takes to run the program. calculate the difference obtained by calls to the method system. currenttimemillis() just before the start of the algorithm and just after the end of the algorithm. calculate the difference obtained by calls to the method system. currenttimemillis() at the start of the program and at the end of the program so that the elapsed time includes the display of the result. use the value returned by the method system. currenttimemillis() just after the end of the algorithm as the elapsed time.
Answers: 3
image
Computers and Technology, 24.06.2019 13:00, juuuuuu42
George heard about the benefits of a data warehouse. he wants to try implementing one for his organization. however, he is afraid that transferring data to the data warehouse will affect transaction time. which element ensures that transactions are not affected when moving data to a warehouse? when data is transferred to a data warehouse, the a area frees the source system to continue transaction processing.
Answers: 2
image
Computers and Technology, 24.06.2019 17:40, orlandokojoasem1234
Write an assembly language program to input a string from the user. your program should do these two things: 1. count and display the number of words in the user input string. 2. flip the case of each character from upper to lower or lower to upper. for example if the user types in: "hello there. how are you? " your output should be: the number of words in the input string is: 5 the output string is : hello there. how are you?
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 in other subjects:

Konu
Mathematics, 11.10.2019 16:20