Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 

Repository files navigation

Function to perform the calculation

def calculate(num1, num2, operation): if operation == '+': return num1 + num2 elif operation == '-': return num1 - num2 elif operation == '*': return num1 * num2 elif operation == '/': if num2 == 0: return "Error: Division by zero is not allowed." return num1 / num2 else: return "Invalid operation. Please choose from +, -, *, or /."

Main program

def main(): # Ask the user for input num1 = float(input("Enter the first number: ")) num2 = float(input("Enter the second number: ")) operation = input("Enter the operation (+, -, *, /): ")

# Perform the calculation
result = calculate(num1, num2, operation)

# Display the result
print(f"{num1} {operation} {num2} = {result}")

Run the program

if name == "main": main()# python-introduction

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors