Question: ANSWER THE FOLLOWING QUESTION IN PYTHON #!/usr/bin/python3 import unittest # -------------------------------------------------------------- # Keyword Cipher # -------------------------------------------------------------- def shuffle_alphabet(word) : ''' Assumes word is a string

ANSWER THE FOLLOWING QUESTION IN PYTHON

#!/usr/bin/python3

import unittest

# --------------------------------------------------------------

# Keyword Cipher

# --------------------------------------------------------------

def shuffle_alphabet(word) :

'''

Assumes word is a string of letters from the English alphabet, where

alphabet = 'abcdefghijklmnopqrstuvwxyz'.

Returns a shuffled version of the above alphabet by the following

steps:

1) Convert word to word2 by deleting multiple occurrences of any

letters, keeping only the first occurrences.

2) Convert word2 to word3, by reversing word2.

3) Create alphabet2 as word3 + alphabet

4) Create alphabet3 by removing multiple occurrences of any letter,

keeping only the first occurrence.

5) Return alphabet3.

For example, if word is 'bunny'

1) word2 is 'buny'

2) word3 is 'ynub'

3) alphabet2 is 'ynubabcdefghijklmnopqrstuvwxyz'

4) alphabet3 is 'ynubacdefghijklmopqrstvwxz'

So shuffle_alphabet('bunny') returns 'ynubacdefghijklmopqrstvwxz'

Hint: the find() function of str will be helpful.

'''

pass

# --------------------------------------------------------------

# The Testing

# --------------------------------------------------------------

class myTests(unittest.TestCase):

def test1(self):

self.assertEqual(shuffle_alphabet('earth'), 'htraebcdfgijklmnopqsuvwxyz')

def test2(self):

self.assertEqual(shuffle_alphabet('bunny'), 'ynubacdefghijklmopqrstvwxz')

def test3(self):

self.assertEqual(shuffle_alphabet('blooming'), 'gnimolbacdefhjkpqrstuvwxyz')

def test4(self):

self.assertEqual(shuffle_alphabet('bloomingbloomingblooming'), 'gnimolbacdefhjkpqrstuvwxyz')

def test5(self):

self.assertEqual(shuffle_alphabet(''), 'abcdefghijklmnopqrstuvwxyz')

def test6(self):

self.assertEqual(shuffle_alphabet('blue'), 'eulbacdfghijkmnopqrstvwxyz')

def test7(self):

self.assertEqual(shuffle_alphabet('science'), 'neicsabdfghjklmopqrtuvwxyz')

if __name__ == '__main__':

unittest.main(exit=True)

# --------------------------------------------------------------

# The End

# --------------------------------------------------------------

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!