From 0c27527a45aad531f1bfa5fbe01d3547c6e88c62 Mon Sep 17 00:00:00 2001 From: zehraturan <78978788+zehraturan@users.noreply.github.com> Date: Mon, 3 Oct 2022 17:01:24 +0200 Subject: [PATCH 1/2] solution of the week2 assignment was added --- question1.py | 15 +++++++++++++++ question2.py | 14 ++++++++++++++ question3.py | 13 +++++++++++++ question4.py | 19 +++++++++++++++++++ 4 files changed, 61 insertions(+) create mode 100644 question1.py create mode 100644 question2.py create mode 100644 question3.py create mode 100644 question4.py diff --git a/question1.py b/question1.py new file mode 100644 index 0000000..876df4a --- /dev/null +++ b/question1.py @@ -0,0 +1,15 @@ +num = int(input("Enter the number of the elements of the list: ")) +k = int(input('Enter how many shifts you want? ' + '\nA positive number for right shifting and a negative number for left shifting: ')) + +my_list = (list(range(num))) +print(my_list) + +if k > 0: #right shift + for i in range(k): + my_list.insert(0,my_list.pop()) +elif k < 0: #left shift + for i in range(abs(k)): + my_list.append(my_list.pop(0)) + +print(my_list) \ No newline at end of file diff --git a/question2.py b/question2.py new file mode 100644 index 0000000..b0391a9 --- /dev/null +++ b/question2.py @@ -0,0 +1,14 @@ +alphabet = "abcdefghijklmnopqrstuvwxyz" + +sentence = input("Enter a sentence please: ").lower().strip() + +result = {} +for letter in sentence: + if letter in alphabet: + if letter in result.keys(): + result[letter] += 1 + else: + result[letter] = 1 + + +print([item for item in sorted(result.items())]) \ No newline at end of file diff --git a/question3.py b/question3.py new file mode 100644 index 0000000..0546f2d --- /dev/null +++ b/question3.py @@ -0,0 +1,13 @@ +import re + +first = input("Enter the first word: ").lower().strip() +first = set(re.sub(r'[^\w\s]', '', first).replace(" ", ""))#remove the punctuations and blanks from the first word +second = input("Enter the second word: ").lower().strip() +second = set(re.sub(r'[^\w\s]', '', second).replace(" ", "")) #remove the punctuations and blanks from the second word + +inters = first & second +f_diff = first - second +s_diff = second - first + +print([''.join(inters), ''.join(f_diff), ''.join(s_diff)]) + diff --git a/question4.py b/question4.py new file mode 100644 index 0000000..7b5734a --- /dev/null +++ b/question4.py @@ -0,0 +1,19 @@ +def palindrome_prime(a,b,c): + first = 1 + max_value = a * b * c + + for i in range(first,int(max_value*0.5)): + if (str(i) == str(i)[::-1]): #checks if it is palindromical + if(i>2): + for j in range(2,i): + is_prime = True + if (i%j==0): + is_prime = False + break + if is_prime: + max_prime = i + + print(f"the nearest palindromical prime number less than {max_value} is ",max_prime) + + + From 3c1323d2f970df0608c6e07c79e5b48437456396 Mon Sep 17 00:00:00 2001 From: zehraturan <78978788+zehraturan@users.noreply.github.com> Date: Wed, 5 Oct 2022 12:33:56 +0200 Subject: [PATCH 2/2] question4 is modified --- question4.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/question4.py b/question4.py index 7b5734a..7ccbc2d 100644 --- a/question4.py +++ b/question4.py @@ -2,7 +2,7 @@ def palindrome_prime(a,b,c): first = 1 max_value = a * b * c - for i in range(first,int(max_value*0.5)): + for i in range(first,int(max_value)): if (str(i) == str(i)[::-1]): #checks if it is palindromical if(i>2): for j in range(2,i):