Skip to content
Open
Show file tree
Hide file tree
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
26 changes: 26 additions & 0 deletions odev_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

from operations import factorial

def pascal_triangle(n):
# Create a list to hold the rows of the triangle
triangle = []

# Loop through each row
for i in range(n):
# Create a list to hold the values in the row
row = []

# Loop through each position in the row
for j in range(i + 1):
# Calculate the value using the binomial coefficient formula
value = int(factorial(i) / (factorial(j) *factorial(i - j)))

# Append the value to the row
row.append(value)

# Append the row to the triangle
triangle.append(row)

return triangle

pascal_triangle(10)
9 changes: 9 additions & 0 deletions odev_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def hyphen_to_sorted():
items=[]
items=[n for n in input('enter an string : ').split('-')]
items.sort()
print('-'.join(items))


hyphen_to_sorted()

15 changes: 15 additions & 0 deletions odev_3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def perfect_number(n):


sum1 = 0
for i in range(1, n):
if(n % i == 0):
sum1 = sum1 + i
if (sum1 == n):
print("The number is a Perfect number!")
else:
print("The number is not a Perfect number!")

n = int(input("Enter any number: "))

perfect_number(n)
Empty file added odev_4.py
Empty file.
75 changes: 75 additions & 0 deletions operations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
def add(a, b):
"""This program adds two
numbers and return the result"""

result = a + b
return result

def subtract(a, b):
"""This program adds two
numbers and return the result"""

result = a - b
return result

def multiply(a, b):
"""This program adds two
numbers and return the result"""

result = a * b
return result

def divide(a, b):
"""This program adds two

numbers and return the result"""

result = a / b
return result

def power(a, b):
"""This program adds two
numbers and return the result"""
result = a ** b
return result

def modulo(a, b):
"""This program adds two
numbers and return the result"""


result = a % b
return result

def sqroot(a):

result = a ** 0.5
return result

result = a ** b
return result

#recurrsion
def factorial(n):
if n<=1: #stop machanizim
return 1
else:
return n*factorial(n-1) #factorial
#factorical (4)
#4*factorical(3)
#4*3*factorial(2)
#4*3*2*factorial(1)
#4*3*2*1


def fib(n):
if n<=2: #stop machanisim
return 1
else :
return fib(n-1)+fib(n-2) #fiboncai function

fib(10)

#it is also possible to define a function

PI = 3.1415926535897932