Page 238 - Computer Science V2.0 Class 11
P. 238
else:
return "Error: Logarithm of non-positive number"
def sine(x):
return math.sin(math.radians(x))
def cosine(x):
return math.cos(math.radians(x))
def calculator():
while True:
print("\nMenu for Logarithm, Sine, and Cosine:")
print("1. Logarithm (log10)")
print("2. Sine")
print("3. Cosine")
print("4. Exit")
choice = input("Enter your choice (1-4): ")
if choice == '4':
break
num1 = float(input("Enter the number: "))
if choice == '1':
result = logarithm(num1)
elif choice == '2':
result = sine(num1)
elif choice == '3':
result = cosine(num1)
else:
print("Invalid choice. Please enter a number from 1 to 4.")
continue
print("Result:", result)
calculator()
SUGGESTED LAB. EXERCISES
1. Write a program to check the divisibility of a number by 7 that is passed as a parameter to the user defined function.
Ans.
def checkDivisibilityBy7(number):
if number % 7 == 0:
return "Divisible by 7"
else:
return "Not divisible by 7"
num = int(input("Enter the number: "))
print(checkDivisibilityBy7(num))
2. Write a program that uses a user defined function that accepts name and gender (as M for Male, F for Female) and prefixes Mr/Ms on
the basis of the gender.
Ans.
def addPrefix(name, gender):
if gender.upper() == 'M':
return "Mr. "+ name
elif gender.upper() == 'F':
224 Touchpad Computer Science (Ver. 2.0)-XI

