0% found this document useful (0 votes)
3 views3 pages

Python Project File PDF

The document provides a Python script that performs basic arithmetic operations based on user input. It prompts the user for two numbers and an operator, then calculates and displays the result. The script includes error handling for division by zero and invalid operators.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Python Project File PDF

The document provides a Python script that performs basic arithmetic operations based on user input. It prompts the user for two numbers and an operator, then calculates and displays the result. The script includes error handling for division by zero and invalid operators.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PYTHON CODING

# Get input for the first number


num1 = int(input("Enter the first number: "))

#Get input for the second number


num2 =int(input("Enter the second number: "))

#Get input for the operator


operator = input("Enter an operator (+, -, *, /): ")

#Perform the calculation based on the operator


ifoperator == '+':
result = num1 + num2
print(num1," + ", num2, "=" ,result)
elifoperator == '-':
result = num1 - num2
print(num1," - ",num2,"=",result)
elifoperator == '*':
result = num1 * num2
print(num1," * ",num2,"=",result)
elifoperator == '/':
if num2 != 0: # Handle division by zero
result = num1 / num2
print(num1," / ",num2," = ",result)
else:
print("Error: Division by zero is not allowed.")
else:
print("Invalid operator entered.")
OUTPUT
CASE1
Enter the first number: 4
Enter the second number: 5
Enter an operator (+, -, *, /): +
4+ 5 = 9

CASE2
Enterthe first number: 5
Enterthe second number: 8
Enteran operator (+, -, *, /): -
5-8= -3

CASE3
Enterthe first number: 8
Enterthe second number: 2
Enteran operator (+, -, *, /): *
8*2= 16

CASE4
Enterthefirst number: 12
Enterthesecond number: 3
Enteranoperator (+, -, *, /): /
12/3=4.0

You might also like