0% found this document useful (0 votes)
16 views

Computer Assignment5

Uploaded by

charles finney
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Computer Assignment5

Uploaded by

charles finney
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

5.

Create a menu driven program using user defined functions to implement a


calculator that performs the following:

a) Basic arithmetic operations (+,-,*,/ )

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

PROGRAM:

a) Basic arithmetic operations (+,-,*,/ )


x = int(input("Enter the first number: "))
y = int(input("Enter the second number: "))
def arithmetic():
print("What would you like to do?")
print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")
print("5. Exit")
n = int(input("Enter your choice:(1-5) "))
if n == 1:
print("The result of addition:",(x + y))
arithmetic()
elif n == 2:
print("The result of subtraction:",(x - y))
arithmetic()
elif n == 3:
print("The result of multiplication:",(x * y))
arithmetic()
elif n == 4:
print("The result of division:",(x / y))
arithmetic()
elif n==5:
return
else:
print("Invalid Choice")
arithmetic()
arithmetic()
B. log10(x), sin(x), cos(x)
Program:
import math
print("What would you like to do?")
print("1. Log10(x)")
print("2. Sin(x)")
print("3. Cos(x)")
n = int(input("Enter your choice(1-3): "))
x = int(input("Enter value of x : "))
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")
OUTPUT:

You might also like