Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Harshita_2310990519_G7 #246

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions Harshita_2310990519_G7
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
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."
else:
return x / y

def power(x, y):
return x ** y

def square_root(x):
if x < 0:
return "Error! Cannot compute square root of a negative number."
else:
return math.sqrt(x)

def factorial(x):
if x < 0:
return "Error! Cannot compute factorial of a negative number."
elif x == 0:
return 1
else:
return x * factorial(x-1)

print("Welcome to the Scientific Calculator by coder harshita!")

while True:
print("\nOperations:")
print("1. Add")
print("2. Subtract")
print("3. Multiply")
print("4. Divide")
print("5. Power")
print("6. Square Root")
print("7. Factorial")
print("8. Quit")

choice = input("\nEnter your choice (1-8): ")

if choice in ['1', '2', '3', '4', '5']:
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
elif choice in ['6', '7']:
num1 = float(input("Enter a number: "))

if choice == '1':
print("Result:", add(num1, num2))
elif choice == '2':
print("Result:", subtract(num1, num2))
elif choice == '3':
print("Result:", multiply(num1, num2))
elif choice == '4':
print("Result:", divide(num1, num2))
elif choice == '5':
print("Result:", power(num1, num2))
elif choice == '6':
print("Result:", square_root(num1))
elif choice == '7':
print("Result:", factorial(num1))
elif choice == '8':
print("Exiting the calculator. Goodbye!")
break
else:
print("Invalid choice! Please enter a valid option.")H