From 176bedc22d8d51daf330c922f0cf01eb43fe64dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CIlter=E2=80=9D?= <“retli79@gmail.com”> Date: Tue, 4 Oct 2022 21:24:06 +0200 Subject: [PATCH 1/4] Answer are added in GitHub --- Answer1.py | 40 ++++++++++++++++++++++++++++++++++++++++ Answer2.py | 23 +++++++++++++++++++++++ Answer3.py | 12 ++++++++++++ Answer4.py | 22 ++++++++++++++++++++++ 4 files changed, 97 insertions(+) create mode 100644 Answer1.py create mode 100644 Answer2.py create mode 100644 Answer3.py create mode 100644 Answer4.py diff --git a/Answer1.py b/Answer1.py new file mode 100644 index 0000000..fd785b9 --- /dev/null +++ b/Answer1.py @@ -0,0 +1,40 @@ +# ### 1. +# Write a program that takes two inputs; one of them is a list +# and the other is a number, +# and returns the list obtained by shifting the elements in the list n places to the right (left) +# when n is positive (negative). +# Use wrap-around: if an element is shifted beyond the end of the list, +# then continue to shift starting at the beginning of the list. + +# ``` +# Example +# Inputs>>> [1, 2, 3, 4, 5], 2 +# Output>>> [4, 5, 1, 2, 3] +# Inputs>>> [1, 2, 3, 4, 5], -2 +# Output>>> [3, 4, 5, 1, 2] +# ``` + +# Python program to right rotate a list by n + +# Returns the rotated list + + +def rotate_function(list, num): + new_list =[] + + for i in range(len(list) - num, len(list)): + new_list.append(list[i]) + + for i in range(0, len(list) -num): + new_list.append(list[i]) + + return new_list + + +enter_list = input([]) +enter_number = int(input()) + +rotate_function(enter_list, enter_number) + + + diff --git a/Answer2.py b/Answer2.py new file mode 100644 index 0000000..b338228 --- /dev/null +++ b/Answer2.py @@ -0,0 +1,23 @@ +# ### 2. +# Write a code snippet that inputs a sentence from the user, +# then uses a dictionary to summarize the number of occurrences of each letter. +# Ignore case, ignore blanks and assume the user does not enter any punctuation. +# Display a two-column table of the letters and their counts with the letters in sorted order. + +# ``` +# Example +# Input >>> "This is a sample text with several words This is more sample text with some different words" +# Output >>> +# [('a', 4), ('d', 3), ('e', 10), ('f', 2), ('h', 4), ('i', 7), ('l', 3), ('m', 4), ('n', 1), ('o', 4), ('p', 2), ('r', 5), ('s', 10), ('t', 9), ('v', 1), ('w', 4), ('x', 2)] +# ``` + +def count_letters(snippet): + result = {} + for letter in snippet.lower(): + if letter.isalpha() and letter not in result: + result[letter] = snippet.count(letter) + return result + +snippet_user = input() + +print(count_letters(snippet_user)) \ No newline at end of file diff --git a/Answer3.py b/Answer3.py new file mode 100644 index 0000000..e84407b --- /dev/null +++ b/Answer3.py @@ -0,0 +1,12 @@ + +word1 = input() +word2 = input() +set1 = set(word1.lower()) +set2 = set(word2.lower()) +lst1 = list(set1&set2) +lst2 = list(set1 - set2) +lst3 = list(set2 - set1) + +print(f"{lst1} {lst2} {lst3}") + + \ No newline at end of file diff --git a/Answer4.py b/Answer4.py new file mode 100644 index 0000000..4e84933 --- /dev/null +++ b/Answer4.py @@ -0,0 +1,22 @@ +### 4. +# A palindromical prime number is a prime number that reads the same when reversed. +# Write a function which returns the nearest palindromical prime number less than the multiplication of all the arguments. + +# ``` +# Example +# Input1>>> some_function(2, 3, 4) +# Output1>>> the nearest palindromical prime number less than 24 +# Input2>>> some_function(31, 77, 99) +# Output2>>> the nearest palindromical prime number less than 236,313 + +def nearest_palindromical_number(num: int): + i = 0 + while True: + small = num - i + if str(small) == str(small)[::-1]: + return(small) + large = num + i + if str(large) == str(large)[::-1]: + return(large) + i += 1 +nearest_palindromical_number(100) \ No newline at end of file From 7a9c1150cbcd50a7cf5307a25b63738678792fe1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CIlter=E2=80=9D?= <“retli79@gmail.com”> Date: Tue, 4 Oct 2022 21:48:16 +0200 Subject: [PATCH 2/4] My amswers are added in GitHub --- Answer2.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/Answer2.py b/Answer2.py index b338228..b72d50a 100644 --- a/Answer2.py +++ b/Answer2.py @@ -11,13 +11,21 @@ # [('a', 4), ('d', 3), ('e', 10), ('f', 2), ('h', 4), ('i', 7), ('l', 3), ('m', 4), ('n', 1), ('o', 4), ('p', 2), ('r', 5), ('s', 10), ('t', 9), ('v', 1), ('w', 4), ('x', 2)] # ``` -def count_letters(snippet): - result = {} - for letter in snippet.lower(): - if letter.isalpha() and letter not in result: - result[letter] = snippet.count(letter) - return result -snippet_user = input() -print(count_letters(snippet_user)) \ No newline at end of file + + + +string =input("içinde hangi harften kaçtane var : ") + +word_dict = {} + +for n in string : + + if n in word_dict : + word_dict[n] +=1 + + else : + word_dict[n] = 1 + +print(word_dict) \ No newline at end of file From 84eb405faa97fcc121fd6c1c9428ac3ff8d4bb2d Mon Sep 17 00:00:00 2001 From: Retli79 <113908207+Retli79@users.noreply.github.com> Date: Tue, 4 Oct 2022 21:55:03 +0200 Subject: [PATCH 3/4] Update Answer2.py --- Answer2.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Answer2.py b/Answer2.py index b72d50a..22412a5 100644 --- a/Answer2.py +++ b/Answer2.py @@ -16,16 +16,13 @@ -string =input("içinde hangi harften kaçtane var : ") +string =input("Enter a sentence ") word_dict = {} - for n in string : - if n in word_dict : word_dict[n] +=1 - else : word_dict[n] = 1 -print(word_dict) \ No newline at end of file +print(word_dict) From 91d759e827b8b3bc8151c83f9416201baea035d1 Mon Sep 17 00:00:00 2001 From: Retli79 <113908207+Retli79@users.noreply.github.com> Date: Tue, 4 Oct 2022 21:55:54 +0200 Subject: [PATCH 4/4] Update Answer1.py --- Answer1.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/Answer1.py b/Answer1.py index fd785b9..916e35c 100644 --- a/Answer1.py +++ b/Answer1.py @@ -21,10 +21,8 @@ def rotate_function(list, num): new_list =[] - for i in range(len(list) - num, len(list)): new_list.append(list[i]) - for i in range(0, len(list) -num): new_list.append(list[i])