From 53970cc34ebabecae7aaeb070a9ca509e2344c23 Mon Sep 17 00:00:00 2001 From: Rumeysa Yakar Date: Tue, 4 Oct 2022 20:07:21 +0200 Subject: [PATCH 1/8] created a function with slicing --- answer1.py | 20 ++++++++++++++++++++ answer2.py | 40 ++++++++++++++++++++++++++++++++++++++++ answer3.py | 23 +++++++++++++++++++++++ answer4.py | 0 4 files changed, 83 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..a9c4ccd --- /dev/null +++ b/answer1.py @@ -0,0 +1,20 @@ +def rotateArray(a, d): + n = len(a) + if d > 0: + a[:] = a[-d:n] + a[:-d] + + # print(a) + if d > n: + d = d % n + print(a) + + else: + a[:] = a[-d:n] + a[:-d] + # print(a) + + return a +list = list(map(int,input('Enter a list?').strip().split())) +number = int(input('Enter a number?')) + +print(rotateArray(list,number)) + diff --git a/answer2.py b/answer2.py new file mode 100644 index 0000000..f67abd1 --- /dev/null +++ b/answer2.py @@ -0,0 +1,40 @@ +sentence = input('Please write a sentence: ') +sentence = sentence.replace(' ', '') +punc = """!()-[]{ };:'"\,<>./?@#$%^&*_~""" +new_form_sentence = ' ' +dict = {} +for i in sentence: + if i not in punc: + new_form_sentence += i + for keys in new_form_sentence: + keys = keys.lower() + keys = keys.strip() + + dict[keys] = dict.get(keys,0) + 1 + new_dict = list(zip(dict.keys(), dict.values())) + +print(str(new_dict)) + + + +# sentence = input('Please write a sentence: ') +# sentence = sentence.replace(' ', '') +# # punc = """!()-[]{ };:'"\,<>./?@#$%^&*_~""" +# # new_form_sentence = ' ' +# # for i in sentence: +# # if i not in punc: +# # new_form_sentence += i +# dict = {} +# punc = """!()-[]{ };:'"\,<>./?@#$%^&*_~""" +# new_form_sentence = ' ' +# for i in sentence: +# if i not in punc: +# new_form_sentence += i +# for keys in new_form_sentence: +# keys = keys.lower() +# keys = keys.strip() + +# dict[keys] = dict.get(keys,0) + 1 +# new_dict = list(zip(dict.keys(), dict.values())) + +# print(str(new_dict)) diff --git a/answer3.py b/answer3.py new file mode 100644 index 0000000..a1eac57 --- /dev/null +++ b/answer3.py @@ -0,0 +1,23 @@ +def common(str1, str2): + str1 = str1.lower() + str2 = str2.lower() + list1 = [] + list2 = [] + punc = """!()-[]{ };:'"\,<>./?@#$%^&*_~""" + for i in str1: + if i not in punc: + list1 += i + for i in str2: + if i not in punc: + list2 += i + + shared_letters = sorted(set(list1) & set(list2)) + unique_to_str1 = sorted(set(list1) - set(list2)) + unique_to_str2 = sorted(set(list2) - set(list1)) + + return ' '.join (str(e) for e in shared_letters), ' '.join(str(e) for e in unique_to_str1), ' '.join(str(e) for e in unique_to_str2) + + +str1 = input('Please type a word: ') +str2 = input('Please type a second word: ') +print(common(str1, str2)) diff --git a/answer4.py b/answer4.py new file mode 100644 index 0000000..e69de29 From d432370fd778c6f3de3b0ae557434a79609af821 Mon Sep 17 00:00:00 2001 From: Rumeysa Yakar Date: Tue, 4 Oct 2022 20:13:35 +0200 Subject: [PATCH 2/8] created a function with slicing --- answer1.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/answer1.py b/answer1.py index a9c4ccd..546fa36 100644 --- a/answer1.py +++ b/answer1.py @@ -3,14 +3,14 @@ def rotateArray(a, d): if d > 0: a[:] = a[-d:n] + a[:-d] - # print(a) + if d > n: d = d % n print(a) else: a[:] = a[-d:n] + a[:-d] - # print(a) + return a list = list(map(int,input('Enter a list?').strip().split())) From 13a5ac78937f342a558dd297bace9dbb3dde6de7 Mon Sep 17 00:00:00 2001 From: Rumeysa Yakar Date: Tue, 4 Oct 2022 20:49:44 +0200 Subject: [PATCH 3/8] created functions --- answer2.py | 26 ++------------------------ answer4.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 24 deletions(-) diff --git a/answer2.py b/answer2.py index f67abd1..9522282 100644 --- a/answer2.py +++ b/answer2.py @@ -4,8 +4,10 @@ new_form_sentence = ' ' dict = {} for i in sentence: + if i not in punc: new_form_sentence += i + for keys in new_form_sentence: keys = keys.lower() keys = keys.strip() @@ -14,27 +16,3 @@ new_dict = list(zip(dict.keys(), dict.values())) print(str(new_dict)) - - - -# sentence = input('Please write a sentence: ') -# sentence = sentence.replace(' ', '') -# # punc = """!()-[]{ };:'"\,<>./?@#$%^&*_~""" -# # new_form_sentence = ' ' -# # for i in sentence: -# # if i not in punc: -# # new_form_sentence += i -# dict = {} -# punc = """!()-[]{ };:'"\,<>./?@#$%^&*_~""" -# new_form_sentence = ' ' -# for i in sentence: -# if i not in punc: -# new_form_sentence += i -# for keys in new_form_sentence: -# keys = keys.lower() -# keys = keys.strip() - -# dict[keys] = dict.get(keys,0) + 1 -# new_dict = list(zip(dict.keys(), dict.values())) - -# print(str(new_dict)) diff --git a/answer4.py b/answer4.py index e69de29..04705d3 100644 --- a/answer4.py +++ b/answer4.py @@ -0,0 +1,11 @@ +# ### 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 +# ``` From 4a34044899e596ecd91b4dbeb9cdc69ae7e72df1 Mon Sep 17 00:00:00 2001 From: Rumeysa Yakar Date: Tue, 4 Oct 2022 20:59:29 +0200 Subject: [PATCH 4/8] created functions --- answer1.py | 4 +--- answer2.py | 1 + answer3.py | 1 + answer4.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/answer1.py b/answer1.py index 546fa36..b8427f1 100644 --- a/answer1.py +++ b/answer1.py @@ -2,15 +2,13 @@ def rotateArray(a, d): n = len(a) if d > 0: a[:] = a[-d:n] + a[:-d] - - + if d > n: d = d % n print(a) else: a[:] = a[-d:n] + a[:-d] - return a list = list(map(int,input('Enter a list?').strip().split())) diff --git a/answer2.py b/answer2.py index 9522282..614297c 100644 --- a/answer2.py +++ b/answer2.py @@ -1,5 +1,6 @@ sentence = input('Please write a sentence: ') sentence = sentence.replace(' ', '') + punc = """!()-[]{ };:'"\,<>./?@#$%^&*_~""" new_form_sentence = ' ' dict = {} diff --git a/answer3.py b/answer3.py index a1eac57..3aebd6b 100644 --- a/answer3.py +++ b/answer3.py @@ -4,6 +4,7 @@ def common(str1, str2): list1 = [] list2 = [] punc = """!()-[]{ };:'"\,<>./?@#$%^&*_~""" + for i in str1: if i not in punc: list1 += i diff --git a/answer4.py b/answer4.py index 04705d3..bd59b7f 100644 --- a/answer4.py +++ b/answer4.py @@ -1,4 +1,4 @@ -# ### 4. +#### 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. From b8c0ebe6c8584fed7f57f80ee10a7abf013bfa94 Mon Sep 17 00:00:00 2001 From: Rumeysa Yakar Date: Tue, 4 Oct 2022 21:39:22 +0200 Subject: [PATCH 5/8] I'm not sure of the solution but wanted to try it. --- answer4.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/answer4.py b/answer4.py index bd59b7f..729bfa9 100644 --- a/answer4.py +++ b/answer4.py @@ -2,10 +2,23 @@ # 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. + +def some_function(a, b, c): + mult = a * b * c + return ('The nearest palindromical prime number less than {}'.format(mult)) + +a = int(input('Please enter first number: ')) +b = int(input('Please enter a second number: ')) +c = int(input('Please enter last number: ')) + +print (some_function(a, b, c)) + + + # ``` # 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 -# ``` +# From 96e1060e1d821d18980eba66bee65e712f43dab5 Mon Sep 17 00:00:00 2001 From: Rumeysa Yakar Date: Tue, 4 Oct 2022 21:42:05 +0200 Subject: [PATCH 6/8] I'm not sure of the solution but wanted to try it. --- answer4.py | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/answer4.py b/answer4.py index 729bfa9..f8abafd 100644 --- a/answer4.py +++ b/answer4.py @@ -1,8 +1,3 @@ -#### 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. - - def some_function(a, b, c): mult = a * b * c return ('The nearest palindromical prime number less than {}'.format(mult)) @@ -13,12 +8,3 @@ def some_function(a, b, c): print (some_function(a, b, c)) - - -# ``` -# 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 -# From cc7af63a25280153bdab76556a07395770f066b9 Mon Sep 17 00:00:00 2001 From: Rumeysa Yakar Date: Tue, 4 Oct 2022 21:47:15 +0200 Subject: [PATCH 7/8] solved --- answer1.py | 1 - answer2.py | 2 +- answer3.py | 2 +- answer4.py | 1 - 4 files changed, 2 insertions(+), 4 deletions(-) diff --git a/answer1.py b/answer1.py index b8427f1..83343d6 100644 --- a/answer1.py +++ b/answer1.py @@ -15,4 +15,3 @@ def rotateArray(a, d): number = int(input('Enter a number?')) print(rotateArray(list,number)) - diff --git a/answer2.py b/answer2.py index 614297c..0b1e1ec 100644 --- a/answer2.py +++ b/answer2.py @@ -16,4 +16,4 @@ dict[keys] = dict.get(keys,0) + 1 new_dict = list(zip(dict.keys(), dict.values())) -print(str(new_dict)) +print(str(new_dict)) \ No newline at end of file diff --git a/answer3.py b/answer3.py index 3aebd6b..9aee8ed 100644 --- a/answer3.py +++ b/answer3.py @@ -21,4 +21,4 @@ def common(str1, str2): str1 = input('Please type a word: ') str2 = input('Please type a second word: ') -print(common(str1, str2)) +print(common(str1, str2)) \ No newline at end of file diff --git a/answer4.py b/answer4.py index f8abafd..b6869da 100644 --- a/answer4.py +++ b/answer4.py @@ -7,4 +7,3 @@ def some_function(a, b, c): c = int(input('Please enter last number: ')) print (some_function(a, b, c)) - From 910f6beebd22c097c750f55110156a4b03b33411 Mon Sep 17 00:00:00 2001 From: Rumeysa Yakar Date: Tue, 4 Oct 2022 21:51:21 +0200 Subject: [PATCH 8/8] I'm not sure of the solution but wanted to try it. --- answer4.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/answer4.py b/answer4.py index b6869da..ca63204 100644 --- a/answer4.py +++ b/answer4.py @@ -6,4 +6,4 @@ def some_function(a, b, c): b = int(input('Please enter a second number: ')) c = int(input('Please enter last number: ')) -print (some_function(a, b, c)) +print (some_function(a, b, c)) \ No newline at end of file