diff --git a/Kabir_2310990705.py b/Kabir_2310990705.py new file mode 100644 index 0000000..6dbcb36 --- /dev/null +++ b/Kabir_2310990705.py @@ -0,0 +1,91 @@ +import math + +def add(x, y): + return x + y + +def subtract(x, y): + return x - y + +def multiply(x, y): + return x * y + +def divide(x, y): + if y == 0: + return "Error! Division by zero is not allowed." + else: + return x / y + +def exponent(x, y): + return x ** y + +def logarithm(x, base): + if x <= 0 or base <= 0: + return "Error! Logarithm base and number must be positive." + else: + return math.log(x, base) + +def sin(x): + return math.sin(x) + +def cos(x): + return math.cos(x) + +def tan(x): + return math.tan(x) + +def sqrt(x): + if x < 0: + return "Error! Square root of negative number is not allowed." + else: + return math.sqrt(x) + +def main(): + print("Select operation:") + print("1.Add") + print("2.Subtract") + print("3.Multiply") + print("4.Divide") + print("5.Exponent") + print("6.Logarithm") + print("7.Sin") + print("8.Cos") + print("9.Tan") + print("10.Square Root") + + choice = input("Enter choice(1/2/3/4/5/6/7/8/9/10): ") + + if choice in ('1', '2', '3', '4', '5'): + num1 = float(input("Enter first number: ")) + num2 = float(input("Enter second number: ")) + + if choice == '1': + print(num1, "+", num2, "=", add(num1, num2)) + elif choice == '2': + print(num1, "-", num2, "=", subtract(num1, num2)) + elif choice == '3': + print(num1, "*", num2, "=", multiply(num1, num2)) + elif choice == '4': + print(num1, "/", num2, "=", divide(num1, num2)) + elif choice == '5': + print(num1, "^", num2, "=", exponent(num1, num2)) + elif choice == '6': + base = float(input("Enter base: ")) + print(num1, "log base", base, "=", logarithm(num1, base)) + + elif choice in ('7', '8', '9', '10'): + num = float(input("Enter number: ")) + + if choice == '7': + print("sin", num, "=", sin(num)) + elif choice == '8': + print("cos", num, "=", cos(num)) + elif choice == '9': + print("tan", num, "=", tan(num)) + elif choice == '10': + print("sqrt", num, "=", sqrt(num)) + + else: + print("Invalid input") + +if __name__ == "main": + main() \ No newline at end of file diff --git a/PythonFunctionCalculator.py b/PythonFunctionCalculator.py deleted file mode 100644 index 9ac9ea1..0000000 --- a/PythonFunctionCalculator.py +++ /dev/null @@ -1,28 +0,0 @@ -print("Calculator to perform operation:: ") -print(" Select a number to perform corresponding action: ") -print( - " 1 for multiplication, 2 for division, 3 for subtraction, 4 for exponent:: " -) - - -def multiplication(num1, num2): - mul = num1 * num2 - print("Multiplication of the two nos. is ::", mul) - - -Operation = int(input("Select the number from 1, 2, 3, 4 ::")) - -num1 = int(input("Enter the first number::")) -num2 = int(input("Enter the Second number::")) - -if (Operation == 1): - multiplication(num1, num2) - -elif (Operation == 2): - division(num1, num2) - -elif (Operation == 3): - subtraction(num1, num2) - -else: - exponent(num1, num2)