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..11e3867 --- /dev/null +++ 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 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