Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions question1.py
Original file line number Diff line number Diff line change
@@ -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)
14 changes: 14 additions & 0 deletions question2.py
Original file line number Diff line number Diff line change
@@ -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())])
13 changes: 13 additions & 0 deletions question3.py
Original file line number Diff line number Diff line change
@@ -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)])

19 changes: 19 additions & 0 deletions question4.py
Original file line number Diff line number Diff line change
@@ -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)):
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)