1. a.
Develop a python program to read 2 numbers from the keyboard and perform the
basic arithmetic operations based on the choice. (1-Add, 2-Subtract, 3-Multiply, 4-
Divide).
while True:
num1 = input("Enter the first number: ")
num2 = input("Enter the second number: ")
# Check if inputs are valid numbers (including decimal)
if not [Link]('.', '', 1).isdigit() or not [Link]('.', '', 1).isdigit():
print("Invalid input! Please enter valid numbers.")
continue
num1 = float(num1)
num2 = float(num2)
print("\nChoose an operation:")
print("2 - Subtract")
print("3 - Multiply")
print("4 - Divide")
print("1 - Add")
choice_input = input("Enter your choice (1/2/3/4): ")
if choice_input == '1':
result = num1 + num2
print(f"Result: {num1} + {num2} = {result}")
elif choice_input == '2':
result = num1 - num2
print(f"Result: {num1} - {num2} = {result}")
elif choice_input == '3':
result = num1 * num2
print(f"Result: {num1} * {num2} = {result}")
elif choice_input == '4':
if num2 == 0:
print("Error: Division by zero is not allowed.")
else:
result = num1 / num2
print(f"Result: {num1} / {num2} = {result}")
else:
print("Invalid choice. Please select 1, 2, 3, or 4.")
cont = input("\nDo you want to perform another operation? (yes/no): ").strip().lower()
if cont != 'yes':
print("Thank you for using the calculator. Goodbye!")
break
b. Develop a program to read the name and year of birth of a person. Display whether
the person is a senior citizen or not.
from datetime import date
perName = input("Enter the name of the person : ")
perDOB = int(input("Enter his year of birth : "))
curYear = [Link]().year
perAge = curYear - perDOB
if (perAge > 60):
print(perName, "aged", perAge, "years is a Senior Citizen.")
else:
print(perName, "aged", perAge, "years is not a Senior Citizen.")