Advertisements
Advertisements
प्रश्न
Create a menu-driven program using user-defined functions to implement a calculator that performs the following:
log10(x), sin(x), cos(x)
संक्षेप में उत्तर
Advertisements
उत्तर
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")shaalaa.com
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
