100% found this document useful (1 vote)
889 views

COSC2429 - Intro To Programming Assessment 2 - Sem A 2021: RMIT Classification: Trusted

This document provides instructions for an assessment involving 4 programming problems. The problems involve writing functions to: 1) return the string from a list with the fewest occurrences of the lowercase letter 'o'; 2) reverse a string split into substrings of a given integer length; 3) calculate shipping fees based on item quantities and warehouse locations; and 4) encrypt and decrypt a string using element symbols and numbers from the periodic table of elements. Functions are to be defined with specific parameters and return types as outlined for each problem.

Uploaded by

roll_witit
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
889 views

COSC2429 - Intro To Programming Assessment 2 - Sem A 2021: RMIT Classification: Trusted

This document provides instructions for an assessment involving 4 programming problems. The problems involve writing functions to: 1) return the string from a list with the fewest occurrences of the lowercase letter 'o'; 2) reverse a string split into substrings of a given integer length; 3) calculate shipping fees based on item quantities and warehouse locations; and 4) encrypt and decrypt a string using element symbols and numbers from the periodic table of elements. Functions are to be defined with specific parameters and return types as outlined for each problem.

Uploaded by

roll_witit
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

RMIT Classification: Trusted

COSC2429 – Intro to Programming


Assessment 2 – Sem A 2021

Please follow the instruction carefully. Please copy the header from the Canvas site and put it at
the top of your py file.
- Please write correct docstrings and code comment.
- There are a total of 4 problems. You must put all the code for all the problems below in 1
py file with your student id (e.g., s12345678.py) and upload it to Assessment 2 on Canvas
once done. DO NOT ZIP FILE PLEASE!
- Do not include test of your function, and NO USER INPUT PLEASE!

Problem 1:
Write a function least_o(lst) in Python that takes one parameter, a list of strings, as input and
returns the string in the list that has the fewest total occurrences of the lowercase letter 'o' (note
that this may be zero occurrences). Uppercase ‘O’s should not be counted

You may assume that no two strings in the list have the same total number of 'o', that there is at
least one string in the list, and that all elements of the list are valid strings.

For example: If you receive the list [‘tooo’, ‘ho’, ‘nO’, ‘loo’], you must return ‘ho’.

Function format:
def least_o(lst):
# your logic here
return s
Note: You can write it either as an iterative or recursive function.

Problem 2:
Write a function the take in a str and an int and return the reverse str split by the int number “almost
evenly”. Some examples:
- If you have a str “12345678” and an int 3, you split it into 3 substrings of 3, 3, and 2
characters. Your return must be “32165487”.
- If you have a str “1234567890123456789” and an int 4, you split it into 4 substrings of 5,
5, 5 and 4 characters. Your return must be “5432109876543219876”.
- If the int to split by is larger than then length of the str, you have to reverse the whole str.

Function format:
def reverse(s, i):
# your logic here
return new_s
RMIT Classification: Trusted

Problem 3:
Write a function to calculate the shipping fee on an ecommerce website. The function will take in
a list and a dict, for example:
shopping_list = [‘apple’, ‘orange’, ‘kiwi’, ‘orange’, ‘apple’, ‘apple’]
location_dict = {
‘apple’: [1,3,4,7],
‘orange’: [2,4,5,7],
‘kiwi’: [1,3,5,6]
}
The shopping_list includes all items the customer put in his/her cart. There can be multiple
occurrences of an item, so you have to sum them up. The location_dict includes the items as keys
of the dict, while the dict values are list of warehouse locations that item is in (int numbers). If
there are items that can be dispatched from the same warehouse, you must combine them to save
the shipping fee for the customer. If they are from different warehouses, you must calculate them
as 2 shipments. The shipping fee will be 20,000VND per shipment. Return the final total shipping
fee and total number of shipments.

Function format:
def shipping_fee(shopping_list, location_dict):
# your logic here
return shipping_fee, number_of_shipments

NOTE: both returns must be int, not float.

Problem 4:
A chemical research lab wants to send some secret data to another lab. To avoid the information
being stolen. They encode it using the periodic table chart:
RMIT Classification: Trusted

IMPORTANT: There can be multiple versions on this table online. Please use this one only.

The rules are:


- If you see a substring that matches one of the elements in the table, you replace it with the
number and VICE VERSA.
- You prioritize the encryption of 2-character substring over 1-character one. For example,
if you have the word “name”, “Na” will be encrypted, not “N”.
- However, for numbers, to keep it simple, we encrypt 1 digit at a time.
- Since the length of the replace string varies, you put them in a {} to ensure the correct
encryption and decryption.
- Please keep all the punctuation and special characters the same.
- For example:
I am 15 year old. => {53} {95} {H}{B} {39}e{18} {8}ld.

Function format:
def encrypt(s):
# your logic here
return encrypted_s
def decrypt(encrypted_s):
# your logic here
return s
NOTE: beware of case sensitive

You might also like