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
18 changes: 18 additions & 0 deletions 1-perfect_number.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""
Perfect number: Perfect number is a positive integer that is equal to the sum of its proper divisors.
The smallest perfect number is 6, which is the sum of 1, 2, and 3.
Some other perfect numbers are 28(1+2+4+7+14=28), 496 and 8128.
Write a function that finds perfect numbers between 1 and 1000.
Check perfect numbers between 1 and 1000 and find the sum of the perfect numbers using reduce and filter functions.
"""
perfect_numbers=[]
for i in range(1,1001):
sum_divisors = 0
for divisor in range(1, i):
if i % divisor == 0:
sum_divisors += divisor

if sum_divisors == i:
perfect_numbers.append(sum_divisors)
print("perfect_numbers:",perfect_numbers)
print("Sum of perfect_numbers:",sum(perfect_numbers))
19 changes: 19 additions & 0 deletions 2-reading_number.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""
Write a function that outputs the transcription of an input number with two digits.
Example:
28--->Twenty Eight
"""


def transcription(number):
t_numbers = {0: 'Zero', 1: 'One', 2: 'Two', 3: 'Three', 4: 'Four', 5: 'Five', 6: 'Six', 7: 'Seven', 8: 'Eight',
9: 'Nine', 10: 'Ten', 11: 'Eleven', 12: 'Twelve', 13: 'Thirteen', 14: 'Fourteen', 15: 'Fifteen',
16: 'Sixteen', 17: 'Seventeen', 18: 'Eighteen', 19: 'Nineteen', 20: 'Twenty', 30: 'Thirty',
40: 'Fourty', 50: 'Fifty', 60: 'Sixty', 70: 'Seventy', 80: 'Eighty', 90: 'Ninety'}
if number in t_numbers:
print(t_numbers[number])
else:
print(t_numbers[number-(number % 10)], t_numbers[number % 10])


transcription(int(input('Enter a number:')))
19 changes: 19 additions & 0 deletions 3-alphabetical_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""
Write a function that takes an input of different words with hyphen (-) in between them and then:

sorts the words in alphabetical order,
adds hyphen icon (-) between them,
gives the output of the sorted words.
Example:

Input >>> green-red-yellow-black-white
Output >>> black-green-red-white-yellow
"""


def sort_alphabetical_order(text):
print('-'.join(sorted(text.split('-')))) # split ile kelimeler ayrılır. Ayrılan kelimeler sorted ile sıralanır
# join ile tekrar biraraya getirilir.


sort_alphabetical_order(input("Kelimeler arasında '-' bırakarak kelimelerinizi yazınız :"))
13 changes: 13 additions & 0 deletions 4-unique_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""
Write a function that filters all the unique(unrepeated) elements of a given list.
Example:
Function call: unique_list([1,2,3,3,3,3,4,5,5])
Output : [1, 2, 3, 4, 5]
"""


def unique_list(n):
print(list(set(n))) # girilen liste set komutu ile herbir elemanı benzersiz olan kümeye cevrilir ve yazdırılır.


unique_list([1, 2, 3, 3, 3, 3, 4, 5, 5])
28 changes: 28 additions & 0 deletions 5-equal_reverse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""
Write a function that controls the given inputs whether they are equal to their reversed order or not.
Example:
Input >>> madam, tacocat, utrecht
Output >>> True, True, False
"""
"""def equal_reverse(text):
words = map(lambda x:x.strip(),text.split(','))
print( [i==i[::-1] for i in words] )

equal_reverse(input())"""


def equal_reverse(text):

words = text.split(",")
result = ""
for x in words:
r_x = x[::-1]
if x == r_x:
result += "True,"
else:
result += "False,"
return print(result)


text = input("Kelimeler arasında ',' bırakarak kelimelerinizi yazınız :")
equal_reverse(text)