diff --git "a/1- Perfect Number Ker\304\261m Sak.py" "b/1- Perfect Number Ker\304\261m Sak.py" new file mode 100644 index 0000000..213313e --- /dev/null +++ "b/1- Perfect Number Ker\304\261m Sak.py" @@ -0,0 +1,46 @@ + +# 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. + +### First Solution ### + +def perfect_numbers(given_number = 1000): # Takes 1000 as an argument if not given + my_list = [x for x in range(1,given_number +1)] # List comprehension + result = [] + + for i in my_list: # Takes every number between 1-1000 + sum_divisors = 0 # sum of the divisors + for y in range(1,i): + if i % y == 0: # Checking for every proper divisors + sum_divisors + = y + + if i == sum_divisors: # Checking the if it is equal to sum of the divisors + result.append(i) + + return (', '.join(map(str, result))) # Print list elements seperated with comas + +print(perfect_numbers()) + + +### Second Solution -> Reduce and Filter wil be added ### + + + + + + + + + + + + + + + + diff --git a/2- Reading Number Kerim.py b/2- Reading Number Kerim.py new file mode 100644 index 0000000..95ee1dd --- /dev/null +++ b/2- Reading Number Kerim.py @@ -0,0 +1,36 @@ +# Write a function that outputs the transcription of an input number with two digits. +# Example: +# 28---------------->Twenty Eight\ + +def reading_number(number): + try: + number = str(number) + + if len(number) != 2: + return ("Enter two digit number!") + + tens_digit_dic = {1:"Ten", 2:"Twenty", 3:"Thirty", 4:"Forty", 5:"Fifty", 6:"Sixty", 7:"Seventy", 8:"Eighty",9:"Ninety"} + units_digit_dic = {1:"One", 2:"Two", 3:"Three", 4:"Four", 5:"Five", 6:"Six", 7:"Seven", 8:"Eight",9:"Nine"} + digits_ten_to_twenty = ["Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"] + + unit_digit = int(number[1]) + ten_digit = int(number[0]) + + if unit_digit == 0: #10,20,30,40... + return (tens_digit_dic[ten_digit]) + elif ten_digit == 1: #11,12,13 + return (digits_ten_to_twenty[unit_digit -1]) + else: + return (tens_digit_dic[ten_digit] + " " + units_digit_dic[unit_digit]) + except: + return ("Please enter a NUMBER!!!") + + +print(reading_number(6)) #Enter two digit number! +print(reading_number(11)) #Eleven +print(reading_number(10)) #Ten +print(reading_number(16)) #Sixteen +print(reading_number(30)) #Thirty +print(reading_number(56)) #Fifty Six +print(reading_number(99)) #Ninety Nine +print(reading_number(999)) # Enter two digit number! diff --git a/3- Alphabetical order Kerim.py b/3- Alphabetical order Kerim.py new file mode 100644 index 0000000..e5ecae4 --- /dev/null +++ b/3- Alphabetical order Kerim.py @@ -0,0 +1,15 @@ +# 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 alphabetical_order(given_words = "green-red-yellow-black-white"): # Takes a string as an argument + return ("-".join(map(str,sorted(list(given_words.split("-")))))) # Makes a sorted list and then joins with "-" sign + +print(alphabetical_order()) + diff --git a/4- Unique list Kerim .py b/4- Unique list Kerim .py new file mode 100644 index 0000000..344c471 --- /dev/null +++ b/4- Unique list Kerim .py @@ -0,0 +1,12 @@ +# 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(given_list): # Takes a list as argument + return list(set(given_list)) # Makes a set with unique elements then makes a list + +print(unique_list([1,2,3,3,3,3,4,5,5])) + diff --git a/5- Equal Reverse Kerim.py b/5- Equal Reverse Kerim.py new file mode 100644 index 0000000..e6844b1 --- /dev/null +++ b/5- Equal Reverse Kerim.py @@ -0,0 +1,19 @@ +# 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(*words): # More then one input + check_list = [] # Empty list + for word in words: + reversed = word[::-1] # reversed word + if word == reversed: # If word is equal to reversed order + check_list.append("True") # add True to list + else: # if not equal + check_list.append("False") # add False to list + return(", ".join(map(str,check_list))) # print list items comma separated + + +print(equal_reverse('madam', "tacocat", "utrecht")) +print(equal_reverse("seles", "merhaba", "beb", "madam"))