add = lambda a, b: a + b
subtract = lambda a, b: a - b
multiply = lambda a, b: a * b
divide = lambda a, b: a / b
while True:
print("""\nEnter
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Exit""")
try:
choice = int(input('\nEnter choice: '))
except:
print('Enter integer values only!')
continue
if 1<=choice<=5:
if choice==5:
print('Exiting...\n')
break
numbers = [int(i) for i in input('Enter numbers: ').split()]
if choice==1:
print('\nResult is: ', add(numbers[0], numbers[1]), '\n')
continue
if choice==2:
print('\nResult is: ', subtract(numbers[0], numbers[1]), '\n')
continue
if choice==3:
print('\nResult is: ', multiply(numbers[0], numbers[1]), '\n')
continue
if choice==4:
print('\nResult is: ', divide(numbers[0], numbers[1]), '\n')
continue
else:
print('Enter choice between 1 and 5')
Output:
PS C:\CopyAssignment.py" Enter 1. Addition 2. Subtraction 3. Multiplication 4. Division 5. Exit Enter choice: ds Enter integer values only! Enter 1. Addition 2. Subtraction 3. Multiplication 4. Division 5. Exit Enter choice: 1 Enter numbers: 1 2 Result is: 3 Enter 1. Addition 2. Subtraction 3. Multiplication 4. Division 5. Exit Enter choice: 4 Enter numbers: 25 4 Result is: 6.25 Enter 1. Addition 2. Subtraction 3. Multiplication 4. Division 5. Exit Enter choice: 9 Enter choice between 1 and 5 Enter 1. Addition 2. Subtraction 3. Multiplication 4. Division 5. Exit Enter choice: 5 Exiting...
Also Read:
- Create your own ChatGPT with Python
- SQLite | CRUD Operations in Python
- Event Management System Project in Python
- Ticket Booking and Management in Python
- Hostel Management System Project in Python
- Sales Management System Project in Python
- Bank Management System Project in C++
- Python Download File from URL | 4 Methods
- Python Programming Examples | Fundamental Programs in Python
- Spell Checker in Python
- Portfolio Management System in Python
- Stickman Game in Python
- Contact Book project in Python
- Loan Management System Project in Python
- Cab Booking System in Python
- Brick Breaker Game in Python
- Tank game in Python
- GUI Piano in Python
- Ludo Game in Python
- Rock Paper Scissors Game in Python
- Snake and Ladder Game in Python
- Puzzle Game in Python
- Medical Store Management System Project in Python
- Creating Dino Game in Python
- Tic Tac Toe Game in Python
- Test Typing Speed using Python App
- Scientific Calculator in Python
- GUI To-Do List App in Python Tkinter
- Scientific Calculator in Python using Tkinter
- GUI Chat Application in Python Tkinter