Skip to content

Commit

Permalink
Merge pull request #16 from Anirbansaha007/main
Browse files Browse the repository at this point in the history
Created calculator.py
  • Loading branch information
3NCRY9T3R authored Oct 6, 2020
2 parents 78fa81b + 9adcbe0 commit 332df85
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
40 changes: 40 additions & 0 deletions calculator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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):
return x / y


print("Select operation.")
print("1.Add")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")

while True:
choice = input("Enter choice(1/2/3/4): ")

if choice in ('1', '2', '3', '4'):
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))
break
else:
print("Invalid Input")
12 changes: 12 additions & 0 deletions factorial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
num = int(input("Enter a number: "))

factorial = 1

if num < 0:
print("Sorry, factorial does not exist for negative numbers")
elif num == 0:
print("The factorial of 0 is 1")
else:
for i in range(1,num + 1):
factorial = factorial*i
print("The factorial of",num,"is",factorial)
19 changes: 19 additions & 0 deletions fibonacci.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
nterms = int(input("How many terms? "))

n1, n2 = 0, 1
count = 0

if nterms <= 0:
print("Please enter a positive integer")
elif nterms == 1:
print("Fibonacci sequence upto",nterms,":")
print(n1)
else:
print("Fibonacci sequence:")
while count < nterms:
print(n1)
nth = n1 + n2
# update values
n1 = n2
n2 = nth
count += 1

0 comments on commit 332df85

Please sign in to comment.