CMPS 1500, Fall 2023
The “Strings-Lists lab”: Using sequence types and loops
Lab point value: 25 points (+5 bonus points possible)
Assigned: Tuesday, September 5 (in lab course)
Due: Moday, September 11, 11:59PM (via gradescope)
Introduction
This semester, you will be solving a lot of lab problems that will involve strings of characters, lists
of items, and using loops (while and for). In order to be prepared to solve larger problems, you
will need to practice your skills!
This Lab assignment will give you lots of practice with:
• string indexing and slicing
• list indexing, slicing, and appending
• membership testing with the in operator
• reading input repeatedly using while
• iterating through a list using for
What you will hand in
This lab assignment contains 6 problems worth 5 points each. You are only required to submit 5 of
them, so if you complete all 6 problems you can earn 5 bonus points. (25 points will be considered
100%) By the time you are finished, you will submit several different python files to Gradescope.
They are:
• login_name.py
• memorable_passwords.py
• clock.py
• password_checker.py
• cake_selection.py
• cake_ordering.py
1
Please submit all files together. You may make partial submissions to test your solutions, but make
sure your final submission contains all files. Please see your TA for help if you aren’t sure how to
do this.
Like all of our submitted work, this is an individual lab assignment. You must turn in only
your own work. Getting help is encouraged, but please be aware of our collaboration policy. All
collaborators must be named and cited in source code comments!
Get the initial handout files from Canvas
The starter lab files are all contained in a zip file called strings-lists-lab.zip which is found
on Canvas.
1 Login name
Your first task is to write a program that creates a login name for a user, given the user’s first
name, last name, and a four-digit number as input.
Your program will read in their first and last name and four-digit number as a single line of input,
and will output their login name, which is made up of the first five letters of the last name, followed
by the first letter of the first name, and then the last two digits of the number (use the % operator).
If the last name has less than five letters, then use all letters of the last name.
1.1 Examples
If the input is:
Yordan Alvarez 1997
Your output should be:
Your login name: AlvarY97
Don’t forget the rule about names shorter than 5 letters. If the input is:
Lil Kim 1974
Your output should be:
Your login name: KimL74
We will test your program on these inputs, and several more with different names and numbers.
Test your program on your own computer, and then submit it to Gradescope when you feel like it
can pass the tests. You can re-submit if there are any problems you need to fix after that.
2 Memorable Passwords
It’s not easy to come up with a secure password that one can actually remember. One of the
methods proposed is to take a line of text and take the first letter of each word to form a password.
An extra step is to substitute certain symbols in place of letters, such as:
2
• “o” with “0
/ ” (zero)
• “a” with “@”
• “l” (lowercase letter L) with “1” (one)
For instance, using “Cookies and Code, we meet on Thursdays” would yield “C@C,wm0T”. Note,
the ’,’ is included. Include basic punctuation characters only when they occur at the end of a word.
Those “basic punctuation” characters which you should include are:
.,;:?!
Write a program that asks the user to enter a phrase and outputs the password that is generated
using these rules. You can assume that the words in the phrase will be separated by a single space,
or a common punctuation sign such as .,?!;: followed by a space. (In other words, punctuation
will only be found at the end of a word)
Related link: xkcd: Password Strength
2.1 Examples
If the input is:
New Orleans, is anywhere better?
Your output should be:
Please enter a phrase: NO,i@b?
Don’t forget about common punctuation:
CMPS1500 is a wonderful course; I love Tulane!
Your output should be:
Please enter a phrase: Ci@wc;I1T!
Note that Please enter a phrase: is the prompt given by the input() function. After that,
your program will simply print the password generated by that phrase.
3 Around the clock
Suppose you’ve been hired by an airport to create a program to determine the expected arrival time
of an incoming aircraft. You must determine the arrival time using only the aircraft’s departure
time and the travel time.
Note the following:
• all times are given in hours and minutes
• don’t worry about time zones
3
• air traffic uses 24 hour time (0000-2359)
• “midnight” is given as 0000, “noon” as 1200, “5:15pm” as 1715
3.1 Inputs your program will receive
You will be given input in the form of two 4-character numeric values. The first number will be
the departure time, always given as four characters in a 24-hour format1 . The second number will
be the travel time in hours and minutes.
Neither input will contain a “:” character. There will be a space between the two numeric values.
You can assume the number of minutes will be between 0 and 59, but the travel time might be
greater than 24 hours.
Your output should be a time, in the same format we describe above: two digit hours (between 0
and 23) and two digit minutes (between 0 and 59).
3.2 Examples
If the input is:
0900 0200
Your output should be:
1100
Be mindful of hour changes:
1040 0322
Your output should be:
1402
The travel time may be longer than 24 hours:
0625 2530
Your output should be (note the starting ’0’):
0755
4 Password strength checker
Note: To solve this problem, you will need to use a while loop. If you need a reminder
of how to do this, refer to Section 4.1 in your zyBooks reading or to this week’s lecture
slides.
1
Some people call this “military time”, but the 24-hour time format is widely used around the world.
4
Many computer systems require that a password meets some criteria to be considered “secure”.
Your job here is to write a program to check some of these criteria.
In this problem, the criteria are that passwords must:
• have a length between 8 and 20 characters (inclusive of 8 and 20)
• not contain spaces
• contain at least one uppercase letter
• contain at least one lowercase letter
• contain at least one number
• and contain at least one special symbol character (! ? , . ; : $ # &).
Write a program that keeps asking the user to enter a password (repeatedly, if necessary) until
their password satisfies the requirements.
4.1 Examples
If the input is:
TulaneRocks1!
Your output should be:
Enter password:
Password Accepted
The user may not enter an acceptable password at first:
new orleans
NewOrleans4
NewOrleans504?$
Your output should be:
Enter password:
Enter password:
Enter password:
Password Accepted
5 Cake selection
There has been a rush on cake, and there is not enough for all students. We need some rules for
who gets cake on which day of the week.
Your boss has come up with some arbitrary rules, which may or may not actually make any sense.
But either way, your program needs adhere to these rules and print out who gets cake on which
days.
Given a list of student names (included in your starter file), your program will determine that on:
5
• Mondays: students with a name containing fewer than 4 letters get cake
• Wednesdays: students who have a name ending in the letter y get cake.
• Fridays: students who have both:
– a name containing the letter r, and also
– a name longer than 4 letters
5.1 Examples
With the student list given in the starter code, your program should print:
On Monday, these students get cake:
Eva
Bob
Mo
Kim
Ari
On Wednesday, these students get cake:
Marty
Gary
Jimmy
On Friday, these students get cake:
Xavier
Priya
Marty
Please note: We will test your program with some other lists of students, so you can’t just print
out those same names every time! (For testing, see if your program still works after making changes
to the student name list.)
6 Cake Ordering (Extra credit, 5 points)
Good news: we now have enough cake for everyone!
The new problem is determining the order we’ll use to serve cake to students.
Suppose you are a TA for the cake-serving class; on the first day of class with cake, students were
served in order of when they arrived to class, which you recorded. The professor for the course
has tasked you with determining the serving order for any future class based on the following (and
somewhat unfair) rules:
• Every seventh class, the student with the longest name should be served first and the student
with the shortest name should be served last; the rest of the order should be preserved relative
to the previous class
• Classes for which the above rule does not apply, each student’s serving place is rotated forward
by one relative to the previous day’s ordering; the student served first on the previous day is
served last
6
Starting from the initial serving order of the first day of class, write a program to output the serving
order for a future class specified by the input. Specifically, input will be provided as a positive
integer. This number represents how many classes into the future the professor would like to see
the serving order for. If ’0’ is entered, the original serving order should be printed.
6.1 Examples
If the input is:
Your output should be:
["Matthew", "Lorraine", "Aron", "Nicholas", "Maddie", "Garrett", "Carola",
"Jihun", "Ramgopal", "Anastasia"]
If the input is:
Your output should be:
["Maddie", "Garrett", "Carola", "Jihun", "Ramgopal", "Anastasia", "Matthew",
"Lorraine", "Aron", "Nicholas"]
If the input is:
Your output should be:
['Anastasia', 'Garrett', 'Carola', 'Jihun', 'Ramgopal',
'Matthew', 'Lorraine', 'Nicholas', 'Maddie', 'Aron']
If the input is:
Your output should be:
['Garrett', 'Carola', 'Jihun', 'Ramgopal', 'Matthew', 'Lorraine',
'Nicholas', 'Maddie', 'Aron', 'Anastasia']