a) Basic arithmetic operations
Program:
#Asking for the user input
x = int(input("Enter the first number: "))
y = int(input("Enter the second number: "))
#printing the Menu
print("What would you like to do?")
print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")
#Asking user about the arithmetic operation choice
n = int(input("Enter your choice:(1-4) "))
#Calculation as per input from the user
if n == 1:
print("The result of addition:",(x + y))
elif n == 2:
print("The result of subtraction:",(x - y))
elif n == 3:
print("The result of multiplication:",(x * y))
elif n == 4:
print("The result of division:",(x / y))
else:
print("Invalid Choice")
b) log10(x), sin(x), cos(x)
Program:
import math
#Providing the Menu to Choose
print("What would you like to do?")
print("1. Log10(x)")
print("2. Sin(x)")
print("3. Cos(x)")
#Asking user about the choice
n = int(input("Enter your choice(1-3): "))
#Asking the number on which the operation should be performed
x = int(input("Enter value of x : "))
#Calculation as per input from the user
if n == 1:
print("Log of",(x),"with base 10 is",math.log10(x))
elif n == 2:
print("Sin(x) is ",math.sin(math.radians(x)))
elif n == 3:
print("Cos(x) is ",math.cos(math.radians(x)))
else:
print("Invalid Choice")