English

Create a menu-driven program using user-defined functions to implement a calculator that performs the following: log10(x), sin(x), cos(x) - Computer Science (Python)

Advertisements
Advertisements

Question

Create a menu-driven program using user-defined functions to implement a calculator that performs the following:

log10(x), sin(x), cos(x)

Answer in Brief

Solution

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
Types of Module - Built-in Modules
  Is there an error in this question or solution?
Chapter 7: Functions - Exercise [Page 172]

APPEARS IN

NCERT Computer Science [English] Class 11
Chapter 7 Functions
Exercise | Q 5. b) | Page 172
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×