0% found this document useful (0 votes)
17 views5 pages

Strings

This document provides instructions for an assignment involving string manipulation in Python. It includes 4 questions to write programs that check for substrings, encode/decode messages with a shift cipher, break a sentence into a comma separated list of lowercase words, and draw a box frame around a repeated message.

Uploaded by

Student 80
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views5 pages

Strings

This document provides instructions for an assignment involving string manipulation in Python. It includes 4 questions to write programs that check for substrings, encode/decode messages with a shift cipher, break a sentence into a comma separated list of lowercase words, and draw a box frame around a repeated message.

Uploaded by

Student 80
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Version 23/08/2023 11:35:33

CSC1015S Assignment 6
Strings

Assignment Instructions
This assignment involves constructing problems that use input and output, ‘if’ and ’if-else’
control flow statements, ‘while’ statements, ‘for’ statements, and statements that perform string
manipulation.
String concepts: string, index, int( ), str( ), find( ), strip( ), slice, concatenation, iteration over.

NOTE Your solutions to this assignment will be evaluated for correctness and for the following
qualities:
• Documentation
o Use of comments at the top of your code to identify program purpose,
author and date.
o Use of comments within your code to explain each non-obvious functional
unit of code.
• General style/readability
o The use of meaningful names for variables and functions.
• Algorithmic qualities
o Efficiency, simplicity
These criteria will be manually assessed by a tutor and commented upon. In this assignment, up to
10 marks will be deducted for deficiencies.

Question One [10 marks]


Write a Python program called sequence.py which checks if a given string is a subsequence
of another. That is, check if the second string is a subsequence of the first string.

A subsequence of a string is a new string that is formed from the original string by deleting
some (can be none) of the characters without disturbing the relative positions of the
remaining characters. (i.e., "ace" is a subsequence of "abcde" while "aec" is not).

Sample IO (The input from the user is shown in bold font – do not program this):
Enter the full string:
9453923
Enter the subsequence to check for:
493
The given substring is a subsequence of the full string.

Page 1 of 5
Version 23/08/2023 11:35:33

Sample IO (The input from the user is shown in bold font – do not program this):
Enter the full string:
This is me
Enter the subsequence to check for:
sisi
The given substring is not a subsequence of the full string.

Question Two [30 marks]

Write a program called ‘shiftcypher.py’ that may be used to encode a message using the shift
cypher.

The shift cypher is a simple technique for coding (and decoding) messages. It involves taking each
letter in the original message and replacing it with one that is a set number of places further along
the alphabet (wrapping around from 'z' back to 'a' if necessary). The number by which each letter is
to be "shifted" is called the key.

If the key is 3, for example, this means that an 'a' will be replaced by an 'd', a 'b' by an 'e', and so on.

Sample IO (The input from the user is shown in bold font – do not program this):

Enter the message:


how now brown cow
Enter the key:
5
Result: mtb stb gwtbs htb

Sample IO (The input from the user is shown in bold font – do not program this):

Enter the message:


mtb stb gwtbs htb
Enter the key:
21
Result: how now brown cow

HINT: Code snippet finding the position of the letter ‘p’:

alphabet=’abcdefghijklmnopqrstuvwxyz’ position = alphabet.find(‘p’)

Page 2 of 5
Version 23/08/2023 11:35:33

Question 3 [30 marks]

Write a program called ‘breakup.py’ that accepts a sentence as input and that outputs it
as a comma-separated list of lowercase words with a full-stop at the end.

Sample IO (The input from the user is shown in bold font – do not program this):
Enter a sentence:
Jerusalema ikhaya LAMI
The word list: jerusalema, ikhaya, lami.

HINT
• To make a comma separated list, you should treat the first item as a separate case before
looping for subsequent items i.e. get the first word and print, then for each subsequent
word, print a comma and space then the word.
• To extract a word at a time, use ‘find()’ to look for the next space.
• Keep breaking down the sentence into the first word and the rest of the sentence. The rest
of the sentence becomes the whole sentence for the next iteration.

NOTE
• Please ensure that your solution ONLY uses Python features introduced in lectures.

Page 3 of 5
Version 23/08/2023 11:35:33

Question 4 [30 marks]

Write a program called ‘messageframe.py’ to draw a frame (made of the characters ‘+’, ‘-‘, and
‘|’) around a message that has been repeated on consecutive lines. There is a space before and after
the message, and no spaces between concentric boxes.

Sample IO (The input from the user is shown in bold font – do not program this):

Enter the message:


Hello World
Enter the message repeat count:
3
Enter the frame thickness:
2
+---------------+
|+-------------+|
|| Hello World ||
|| Hello World ||
|| Hello World ||
|+-------------+|
+---------------+

Sample IO (The input from the user is shown in bold font – do not program this):

Enter the message:


I Love UCT
Enter the message repeat count:
4
Enter the frame thickness:
6
+----------------------+
|+--------------------+|
||+------------------+||
|||+----------------+|||
||||+--------------+||||
|||||+------------+|||||
|||||| I Love UCT ||||||
|||||| I Love UCT ||||||
|||||| I Love UCT ||||||
|||||| I Love UCT ||||||
|||||+------------+|||||
||||+--------------+||||
|||+----------------+|||
||+------------------+||
|+--------------------+|
+----------------------+

Page 4 of 5
Version 23/08/2023 11:35:33

Sample IO (The input from the user is shown in bold font – do not program this):

Enter the message:


Programming is fun!
Enter the message repeat count:
8
Enter the frame thickness:
8
+-----------------------------------+
|+---------------------------------+|
||+-------------------------------+||
|||+-----------------------------+|||
||||+---------------------------+||||
|||||+-------------------------+|||||
||||||+-----------------------+||||||
|||||||+---------------------+|||||||
|||||||| Programming is fun! ||||||||
|||||||| Programming is fun! ||||||||
|||||||| Programming is fun! ||||||||
|||||||| Programming is fun! ||||||||
|||||||| Programming is fun! ||||||||
|||||||| Programming is fun! ||||||||
|||||||| Programming is fun! ||||||||
|||||||| Programming is fun! ||||||||
|||||||+---------------------+|||||||
||||||+-----------------------+||||||
|||||+-------------------------+|||||
||||+---------------------------+||||
|||+-----------------------------+|||
||+-------------------------------+||
|+---------------------------------+|
+-----------------------------------+
Submission
Create and submit a .Zip file called ‘ABCXYZ123.zip’ (where ABCXYZ123 is YOUR
student number) containing subsequence.py, shiftcypher.py, breakup.py
and messageframe.py.

Page 5 of 5

You might also like