Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

#part 1

print('part-1 output')

prefixes = 'JKLMNOPQ'

suffix = 'ack'

for letter in prefixes:

if letter =='O' or letter =='Q':

print(letter + 'u'+suffix)

else:

print( letter + suffix)

#part 2

print('output of example-1')

example = 'extrapple'

z = len(example)

#example-1

def one_example():

y=0

while y < z :

one_slice=example[:-y] # minus value is valid for index

print(one_slice)

y = y+1

#for minus index, it starts from -1 value that belong to the last character of the string.

#The minus indexes belonging to characters flow from the last character to the begining of the strings
decreasingly by one.

one_example()
#example-2

print('example-2 output')

def re_string (n):

two_slice = example[:n]

third_slice = example[n:]

result_slice = two_slice + third_slice

#From adding these slices, checking whether two slices can get back to the original string by
concatenation.

if n < z and result_slice == example:

print ('True')

# adding two slices is legal, and by concatenation, the original string can be got back.

re_string(5)

#example 3

print('example- 3 output')

def nested_slice():

x=-1

z=len(example)

v=-z

while x > v-1:

if x != v:

nested_example = example [x:][x-1:][v:] # nested slics' indexes! The last brackets extracts slics
from the example string.

#The next left side bracket extracts from the next right side bracket's extracted string, and so on
till the begining of the brackets list.

print(nested_example)

x=x-1

else:

print(example)

x=x-1
nested_slice()

You might also like