Skip to document

5. Control and Strings

Assignment on control and string
Course

Computer science1015 (CSC1015F)

257 Documents
Students shared 257 documents in this course
Academic year: 2024/2025
Uploaded by:
0followers
14Uploads
2upvotes

Comments

Please sign in or register to post comments.

Preview text

CSC1015S Assignment 5

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 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., "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.

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 [20 marks]

Write a program called ‘shiftcypher’ 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(‘p’)

Question 4 [20 marks]

Write a program called ‘messageframe’ 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 ||||||
|||||+------------+|||||
||||+--------------+||||
|||+----------------+|||
||+------------------+||
|+--------------------+|
+----------------------+

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’ (where ABCXYZ123 is YOUR

student number) containing subsequence, shiftcypher, breakup

and messageframe.

Was this document helpful?

5. Control and Strings

Course: Computer science1015 (CSC1015F)

257 Documents
Students shared 257 documents in this course
Was this document helpful?
Version 2024/08/15 08:30:35
Page 1 of 5
CSC1015S Assignment 5
Strings
Assignment Instructions
This assignment involves constructing problems that use input and output, ‘ifandif-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 fontdo 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.