From c0045a592d41dd34bcd90e5f73167be0833421c7 Mon Sep 17 00:00:00 2001 From: Theakers Date: Tue, 28 Sep 2021 13:18:16 +0200 Subject: [PATCH 1/2] The answers of the third week --- alphabetical_order.py | 8 ++++++++ equal_reverse.py | 0 perfect_number.py | 12 ++++++++++++ reading_number.py | 13 +++++++++++++ unique_list.py | 8 ++++++++ 5 files changed, 41 insertions(+) create mode 100644 alphabetical_order.py create mode 100644 equal_reverse.py create mode 100644 perfect_number.py create mode 100644 reading_number.py create mode 100644 unique_list.py diff --git a/alphabetical_order.py b/alphabetical_order.py new file mode 100644 index 0000000..6935593 --- /dev/null +++ b/alphabetical_order.py @@ -0,0 +1,8 @@ +#alphabetical order +def alphabetical(): + words=input("Enter some words and add hyphen between them: ") #I wanted to ask from user to enter some words with hyphen + source=[n for n in words.split('-')] #I defined a source list and it is equal all of the words with hyphen + source.sort() #I sorted the list with an alphabetical order + print('-'.join(source))# I wrote to the screen a print which added hyphen + +alphabetical() \ No newline at end of file diff --git a/equal_reverse.py b/equal_reverse.py new file mode 100644 index 0000000..e69de29 diff --git a/perfect_number.py b/perfect_number.py new file mode 100644 index 0000000..67672da --- /dev/null +++ b/perfect_number.py @@ -0,0 +1,12 @@ +#perfect numbers +from functools import reduce # I called the reduce from functools +def perfect_number(n): + sum = 0 # I defined sum and it is equal to 0 + for x in range(1, n): #I returned the function to the number that user enter it. + if n % x == 0: #if the remainder of the division is equal 0 + sum += x #add x to the sum + return sum == n #return it if sum equal to n which is entered by the user. +new_list=list(filter(perfect_number,range(1,1000))) #I defined a new list and it is equal to a new list which is filter by the function +sum=reduce(lambda a,b: a+b,new_list)#sum is equal to a number which is the sum of perfect numbers +print (new_list) +print(sum) \ No newline at end of file diff --git a/reading_number.py b/reading_number.py new file mode 100644 index 0000000..e8c5fb2 --- /dev/null +++ b/reading_number.py @@ -0,0 +1,13 @@ +#reading numbers +def reading_numbers(): # I defined a fuction + x=int(input("Please a number with two digits: ")) #I wanted to ask from user to enter a number with two digits + list=["ten","eleven","twalf","thirteen","fourteen","fifteen","sixteen","seventeen","ëighteen","nineteen"] # I defined three lists + first_digit=["","one","two","three","four","five","six","seven","eight","nine"] + second_digit=["","","twenty","thirty","fourty","fifty","sixty","seventy","eighty","ninety"] + first=x%10 #I defined first is equal the first digit of the number + second=x//10 # I defined second is equal to the second digit of the number + if 10<=x<20: # if the number equal to ten or small than twenty + print(list[first]) # I wanted to print to the elememt of the list which is order in the first position + else: + print(second_digit[second],first_digit[first])# if it is others the reading of the number equal to second postion of the secondigit list +reading_numbers() #and first position of the firstdigit list \ No newline at end of file diff --git a/unique_list.py b/unique_list.py new file mode 100644 index 0000000..0d62fbc --- /dev/null +++ b/unique_list.py @@ -0,0 +1,8 @@ +#unique list +def unique_list(*args): #I defined a function with args + new_list=[] # I opened a new list + for i in args: #For every lements in args + if i not in new_list: #I wanted to search if this element is not in args + new_list.append(i) #if the element doesn't exist in new list I add with the append properties + return new_list # I wanted to take this new list from the function +print(unique_list(1,2,3,3,4,4,6,6,4,5,5)) \ No newline at end of file From 7be0a4d672acc7886ca9b58ee694ec285c96ab5b Mon Sep 17 00:00:00 2001 From: Theakers Date: Tue, 28 Sep 2021 22:10:46 +0200 Subject: [PATCH 2/2] The answers of the third week --- equal_reverse.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/equal_reverse.py b/equal_reverse.py index e69de29..11e3867 100644 --- a/equal_reverse.py +++ b/equal_reverse.py @@ -0,0 +1,10 @@ +#equal deverse +def equal_devers(*args): #I defined a function with args + words=[] #I opened a new empty list + for i in args: #I wanted to look all elements + if i==i[::-1]: #If their reverse is equal to them + words.append(True) #If it is equal I added True to the words list + else: + words.append(False) # If it is not equal I added False to the words list + return words #I wanted to return words list from the function +print(equal_devers("madam","tacocat","utrecht")) \ No newline at end of file