diff --git a/answer1.py b/answer1.py new file mode 100644 index 0000000..83343d6 --- /dev/null +++ b/answer1.py @@ -0,0 +1,17 @@ +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())) +number = int(input('Enter a number?')) + +print(rotateArray(list,number)) diff --git a/answer2.py b/answer2.py new file mode 100644 index 0000000..0b1e1ec --- /dev/null +++ b/answer2.py @@ -0,0 +1,19 @@ +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)) \ No newline at end of file diff --git a/answer3.py b/answer3.py new file mode 100644 index 0000000..9aee8ed --- /dev/null +++ b/answer3.py @@ -0,0 +1,24 @@ +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)) \ No newline at end of file diff --git a/answer4.py b/answer4.py new file mode 100644 index 0000000..ca63204 --- /dev/null +++ b/answer4.py @@ -0,0 +1,9 @@ +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)) \ No newline at end of file