Welcome to Westonci.ca, the place where your questions find answers from a community of knowledgeable experts. Get quick and reliable solutions to your questions from a community of seasoned experts on our user-friendly platform. Connect with a community of professionals ready to help you find accurate solutions to your questions quickly and efficiently.
Sagot :
The program is an illustration of functions
What are functions?
Functions are collections of code segments, that are executed when called or evoked
The program
The program in Python, where comments are used to explain each line is as follows
#This defines the add function
def add(num1,num2):
return(num1, "+", num2,"=", num1 + num2)
#This defines the subtract function
def subtract(num1,num2):
return(num1, "-", num2,"=", num1 - num2)
#This defines the multiply function
def multiply(num1,num2):
return(num1, "*", num2,"=", num1 * num2)
#This defines the divide function
def divide(num1,num2):
return(num1, "/", num2,"=", num1 / num2)
#The main method begins here
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(add(num1,num2))
elif operation == "subtract":
print(subtract(num1,num2))
elif operation == "multiply":
print(multiply(num1,num2))
elif operation == "divide":
print(divide(num1,num2))
else:
print("Not a valid operation.")
Read more about functions at:
https://brainly.com/question/14284563
Thank you for visiting our platform. We hope you found the answers you were looking for. Come back anytime you need more information. Thank you for visiting. Our goal is to provide the most accurate answers for all your informational needs. Come back soon. Thank you for trusting Westonci.ca. Don't forget to revisit us for more accurate and insightful answers.