Question

Define a function math(num1, num2, operation) that takes three arguments and it should perform math operations...

Define a function math(num1, num2, operation) that takes three arguments and it should perform math operations ( +,-,* and /) on two numbers num1 and num2 based on the operation symbol, and then it should return the result. The main part of the program should prompt users to provide num1, num2, and an operation symbol separately and then call the function with user inputs and display the result back to the user.

Function definition should look like this in your module file:

def math(num1 ,num2, operation):

#function statements

Homework Answers

Answer #1
def math(num1, num2, operation):
    if operation == '+':
        return num1 + num2
    elif operation == '-':
        return num1 - num2
    elif operation == '*':
        return num1 * num2
    elif operation == '/':
        return num1 / num2
    else:
        return "Invalid operation"


def main():
    num1 = float(input("Enter first number: "))
    num2 = float(input("Enter second number: "))
    operation = input("Enter operator: ")
    print("Result:", math(num1, num2, operation))


main()

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
1. Write a function called compute_discount which takes a float as the cost and a Boolean...
1. Write a function called compute_discount which takes a float as the cost and a Boolean value to indicate membership. If the customer is a member, give him/her a 10% discount. If the customer is not a member, she/he will not receive a discount. Give all customers a 5% discount, since it is Cyber Tuesday. Return the discounted cost. Do not prompt the user for input or print within the compute_discount function. Call the function from within main() and pass...
You recently started working in at a University in the Math department as a software programmer....
You recently started working in at a University in the Math department as a software programmer. You need to build an app that can calculate the mod of two numbers. Users need to enter num1 and num2. The app should perform the calculation and display the output as num1 mod nub2 operation. For example, 25 mod 5=0 24 mod 5 = 4 Once you implement the mod operations, then you need to add following buttons. Addition Subtraction Division Power Follow...
Function Example: Write a Python function that receives two integer arguments and writes out their sum...
Function Example: Write a Python function that receives two integer arguments and writes out their sum and their product. Assume no global variables. def writer(n1, n2): sum = n1 + n2 product = n1*n2 print("For the numbers", n1, "and", n2) print("the sum is", sum) print("and the product is", product) ... 1) Create a PYHW2 document that will contain your algorithms in flowchart and pseudocode form along with your screen shots of the running program. 2) Create the algorithm in both...
Must satisfy the following: Define a function named series. This function will accept two arguments, both...
Must satisfy the following: Define a function named series. This function will accept two arguments, both integers, named base and span. The function will compute the sum of the integers, starting at the value of base and down to 0 (zero) that are span apart. In other words, if base is 19 and span is 3, series will compute the sum of 19 + 16 + 13 + 10 + 7 + 4 + 1. The series function does not...
Subject- ( App Development for Web) ( language C#, software -visual studio) Exact question is-Firstly the...
Subject- ( App Development for Web) ( language C#, software -visual studio) Exact question is-Firstly the console calculator is created which perform multiply,divide,sub and add, operation and it accept all type of data (divide by 0 case as well ).Now the main motive is to create the library project from the console calculator project .Than we have to create a unit test project which test the functionality of added library.Make test like Test 1. multiply two positive number,Test 2. Add...
Questions: 1. (5 marks) Create a VB.NET Console Application that defines a function Smallest and calls...
Questions: 1. Create a VB.NET Console Application that defines a function Smallest and calls this function from the main program. The function Smallest takes three parameters, all of the Integer data type, and returns the value of the smallest among the three parameters. The main program should (1) Prompt a message (using Console.WriteLine) to ask the user to input three integers. (2) Call the built-in function Console.ReadLine() three times to get the user’s input. (3) Convert the user’s input from...
Create a program that generates a file of random numbers, and then prints them in neat...
Create a program that generates a file of random numbers, and then prints them in neat fashion to another file, and also saves to that file the average and standard deviation of those numbers. I) First, you would need to generate a file of random numbers that consists of N random numbers (100 < N < 1000). Each random digit should be a real number (type double) between 0 and 50. This file and its digits would now serve as...
Module 4 Assignment 1: Pseudocode & Python with Variable Scope Overview Module 4 Assignment 1 features...
Module 4 Assignment 1: Pseudocode & Python with Variable Scope Overview Module 4 Assignment 1 features the design of a calculator program using pseudocode and a Python program that uses a list and functions with variable scope to add, subtract, multiply, and divide. Open the M4Lab1ii.py program in IDLE and save it as M4Lab1ii.py with your initials instead of ii. Each lab asks you to write pseudocode that plans the program’s logic before you write the program in Python and...
##4. What will the following program display? ##def main(): ## x = 1 ## y =...
##4. What will the following program display? ##def main(): ## x = 1 ## y = 3.4 ## print(x, y) ## first printing ## change_us(x, y) ## print(x, y) ##second printing ## ##def change_us(a, b): ## a = 0 ## b = 0 ## print(a, b) ## ##main() ## ##Yes, yes, main() displays ##1 3.4 ##0 0 ##1 3.4 ## The question is: why x and y are still the same while the second printing of (x,y)? ## It seems...
I NEED TASK 3 ONLY TASK 1 country.py class Country:     def __init__(self, name, pop, area, continent):...
I NEED TASK 3 ONLY TASK 1 country.py class Country:     def __init__(self, name, pop, area, continent):         self.name = name         self.pop = pop         self.area = area         self.continent = continent     def getName(self):         return self.name     def getPopulation(self):         return self.pop     def getArea(self):         return self.area     def getContinent(self):         return self.continent     def setPopulation(self, pop):         self.pop = pop     def setArea(self, area):         self.area = area     def setContinent(self, continent):         self.continent = continent     def __repr__(self):         return (f'{self.name} (pop:{self.pop}, size: {self.area}) in {self.continent} ') TASK 2 Python Program: File: catalogue.py from Country...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT