Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

Python function

This document contains a Python program that implements a simple calculator with functions for addition, subtraction, multiplication, and division. It prompts the user to select an operation and input two numbers, then performs the chosen calculation and displays the result. The program also includes error handling for invalid operation selections.

Uploaded by

jubainsolution
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Python function

This document contains a Python program that implements a simple calculator with functions for addition, subtraction, multiplication, and division. It prompts the user to select an operation and input two numbers, then performs the chosen calculation and displays the result. The program also includes error handling for invalid operation selections.

Uploaded by

jubainsolution
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

# Python program for simple calculator

# Function to add two numbers

def add(num1, num2):

return num1 + num2

# Function to subtract two numbers

def subtract(num1, num2):

return num1 - num2

# Function to multiply two numbers

def multiply(num1, num2):

return num1 * num2

# Function to divide two numbers

def divide(num1, num2):

return num1 / num2

print("Please select operation -\n" \

"1. Add\n" \

"2. Subtract\n" \

"3. Multiply\n" \

"4. Divide\n")

# Take input from the user

select = int(input("Select operations form 1, 2, 3, 4 :"))

number_1 = int(input("Enter first number: "))


number_2 = int(input("Enter second number: "))

if select == 1:

print(number_1, "+", number_2, "=",

add(number_1, number_2))

elif select == 2:

print(number_1, "-", number_2, "=",

subtract(number_1, number_2))

elif select == 3:

print(number_1, "*", number_2, "=",

multiply(number_1, number_2))

elif select == 4:

print(number_1, "/", number_2, "=",

divide(number_1, number_2))

else:

print("Invalid input")

You might also like