diff --git a/alphabetic_order.py b/alphabetic_order.py new file mode 100644 index 0000000..71b76d4 --- /dev/null +++ b/alphabetic_order.py @@ -0,0 +1,11 @@ +"""This function 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.""" + + +def sorter(): + elements=input("Enter words which you want to sort(split with hyphen '-': ").split('-') + #inputs will be in elements list,afterwards we use sort() for sorting list + elements.sort() + return('-'.join(elements)) #join() method separates with '-' +print(sorter()) \ No newline at end of file diff --git a/equal_reverse.py b/equal_reverse.py new file mode 100644 index 0000000..941bd1a --- /dev/null +++ b/equal_reverse.py @@ -0,0 +1,20 @@ + +# We check given list elements whether palindrome(equal its reversed order) + + + +def palindrome_chck(): + # Initially we ask for enter list where elements splitted by coma + lis=input("Check list elements whether palindrome(split with comma ',') :").split(',') + control=[] #We check every each words individually by "For Loop",afterwards add results in this list. + for i in lis: + if i==i[::-1]: + control.append(True) + else: + control.append(False) + + return(control) #Results will be shown here as same order with given list due to list.append +print(palindrome_chck()) + + + diff --git a/name_capitalize.py b/name_capitalize.py new file mode 100644 index 0000000..97e1ac2 --- /dev/null +++ b/name_capitalize.py @@ -0,0 +1,15 @@ +"""This func ensures that the first and last names of people begin with a +capital letter in their passports. For example, +alison heck should be capitalised correctly as Alison Heck.""" + +#to capitalize the given full name appropriately. +# capitalize() method converts first letter of words to a capital letter +def name_check(): + n_list=input("Write your full name splitted with space ' ') : ").split(' ') + name=(n_list[0]).capitalize() + surname=(n_list[1]).capitalize() + fullname=[name,surname] + Cap_f_n_=(" ".join(fullname)) + return(Cap_f_n_) + +print(name_check()) \ No newline at end of file diff --git a/name_capitalize2.py b/name_capitalize2.py new file mode 100644 index 0000000..f64efed --- /dev/null +++ b/name_capitalize2.py @@ -0,0 +1,8 @@ +def name_check(): + n_list=input("Write your full name splitted with space ' ') : ").split(' ') + cname=[] + for i in n_list: + i=(i).capitalize() + cname.append(i) + return (" ".join(cname)) +print(name_check()) \ No newline at end of file diff --git a/nr_reader.py b/nr_reader.py new file mode 100644 index 0000000..b8b2c97 --- /dev/null +++ b/nr_reader.py @@ -0,0 +1,15 @@ +#Write a function that outputs the transcription of an input number with two digits. + + +def nr_reader(): + nr_list = list(input("Enter a double digits number : "))#we convert to list for indexing given number + + x=int(nr_list[0]) #indexed units converted to integer,we will use as keys to call assigned values in dictionary + y=int(nr_list[1]) + #we need dictionaries to asiggn indexed keys to their string values + onluk={1:"on",2:"Yirmi",3:"Otuz",4:"Kirk",5:"Elli",6:"Altmis",7:"Yetmis",8:"Seksen",9:"Doksan"} + birlik={0:"",1:"bir",2:"iki",3:"uc",4:"dort",5:"bes",6:"alti",7:"yedi",8:"sekiz",9:"dokuz"} + #We use Turkish to make it clear :D + sayiyazi=onluk[x]+birlik[y] #calling values for each digit to print,adjacent values due to sum str + return(sayiyazi) +print(nr_reader()) \ No newline at end of file diff --git a/perfect_nr.py b/perfect_nr.py new file mode 100644 index 0000000..767f1b0 --- /dev/null +++ b/perfect_nr.py @@ -0,0 +1,20 @@ + +"""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). +This function finds perfect numbers between 1 and 1000. +And find the sum of these perfect numbers using reduce and filter functions additionally.""" + + +from functools import reduce +def perfect_nr(n): + sum = 0 + for x in range(1, n): + if n % x == 0: #checking positive divisors whether remainder is zero + sum += x #adding every each divisors + return sum == n #If given number is a perfect ,then this will be True + #filter function gathers perfect numbers(which return True) +print("Perfect numbers lower than 1000 :",list(filter(perfect_nr,range(2,1001)))) + +print("Sum of perfect numbers lower than 1000 :",reduce(lambda x,y: x+y,list(filter(perfect_nr,range(2,1001))))) +# use reduce function to adding all perfect numbers lower than 1000. \ No newline at end of file diff --git a/unique_lst.py b/unique_lst.py new file mode 100644 index 0000000..fc2695a --- /dev/null +++ b/unique_lst.py @@ -0,0 +1,10 @@ +#We prevent user from repeating.Repeated elements in given list will be expelled. + + +def unique_list(): + elements=input("Avoiding repeating(split with comma ',') :").split(',') + # Initially we ask for enter list where elements splitted by coma + elements=set(elements) #Due to set property ,repeated element will be expelled. + elements=list(elements) #We revert set to list for print as a list. + return(elements) +print(unique_list())