diff --git a/1-perfect_number.py b/1-perfect_number.py new file mode 100644 index 0000000..29df034 --- /dev/null +++ b/1-perfect_number.py @@ -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)) \ No newline at end of file diff --git a/2-reading_number.py b/2-reading_number.py new file mode 100644 index 0000000..3613c4a --- /dev/null +++ b/2-reading_number.py @@ -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:'))) diff --git a/3-alphabetical_order.py b/3-alphabetical_order.py new file mode 100644 index 0000000..4f9dbe3 --- /dev/null +++ b/3-alphabetical_order.py @@ -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 :")) diff --git a/4-unique_list.py b/4-unique_list.py new file mode 100644 index 0000000..ddfeff9 --- /dev/null +++ b/4-unique_list.py @@ -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]) diff --git a/5-equal_reverse.py b/5-equal_reverse.py new file mode 100644 index 0000000..96bb173 --- /dev/null +++ b/5-equal_reverse.py @@ -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)