Assignment Part B
Assignment Part B
Assignment Overview:
Assignments task you with applying the skills and knowledge you have learnt through the Ed
Lessons. They are no more difficult than the exercises in your Ed Lessons. You must meet all
competency requirements for each task to be marked as competent overall on the
assignment.
In Assignment Part B, we're going to continue to use our programming skills to customize and display
data for a user. These are basic examples of how many of the apps and websites you use every day
work. We've continued to look at some features of a fictional USyd Music app, an app like Spotify or
Apple Music that allows users to stream their favourite music.
Assignment Part B requires you to complete 5 tasks here in Ed Lessons;
Music Wrapped (Part 1)
Song Information
Music Wrapped (Part 2)
Song queues (Part 1)
Song queues (Part 2)
It should take you between 4 and 10 hours to complete, but do not leave it until the last minute to
attempt.
General instructions:
Please avoid changing function signatures
Assume that cases not mentioned in the specification will not be tested
Hard coding to pass test cases rather than constructing meaningful programs will result in a NSI
result return.
Missing code comments will result in a NI result return
Please avoid writing programs that are overly complex for the sake of it to "aim for a C*". C* is
designed to award work that is well structured, nuanced, and shows good/deep thinking about
code structure. It is inherent traits of your programming skills, as opposed to a list of things we
are looking for.
MAKE SURE YOU READ THE COMPETENCY REQUIREMENTS CAREFULLY!You must complete your code review in your schedule lab during week 9.
Competency requirements:
The competency requirements are summarized below (but are also listed on the page for each task).
You must meet all requirements to be awarded a Competent (C) for a question.
You must receive a minimum of Competent (C) for all questions to receive a Competent (C)
grade overall and move onto Assignment Part C.
To receive an Above Competent (C*) overall, you must receive an Above Competent (C*) in 3/5 tasks.
Full competency requirements outlined -
https://canvas.sydney.edu.au/courses/59287/pages/assignment-part-b-overview?
module_item_id=2431178 Testing vs Submitting Your Assignment
We have changed the interface to make it easier for us to determine when late submissions are
submitted. What this means for you is that you can use the 'test' button as many times as you would
like before officially submitting the assignment (bottom right hand side of the workspace). To
officially lodge your submission you will need to use the 'submit' button (top right hand side of the
workspace).
Any press of the submit button after 11:59pm on 22nd September will be counted as a late
submission. Late penalties will apply if you do not have special considerations or an academic
accommodations plan. Understanding Test Case Output
There will be 3 main types of test cases:
(UNIT) - Tests individual functions to check actions such as return values or modification of
attributes of an instance
(IO) - Tests a function to check if the values printed to stdout (terminal) is what was expected
(IO-UNIT) - Mix of Unit and IO where both return values, modification of attributes and stdout
will be tested altogether
Have a look at the examples below for a better understanding!
Example 1 [UNIT]
On the header you can find the information on what is being tested:
[Song] : Class/function being tested.
Constructor : Brief description of the test case.You will find the relevant output under Test Case Output where:
A brief description will tell you how your function/method was called. e.g with what
arguments.
Expected is what the the test case was expecting your function to do.
Got is what your function did/returned.
############## <END> ############# is a marker showing the end of the
expected/actual block (not to be printed or returned by your function).
Additional comments will give you additional information on the error. In this case, the
duration attribute is not correctly set
Example 2 [IO]
The header is similar to the previous exampleHighlighted in Green (+): Your program did not produce/output that line
Highlighted in Red (-): Your program produced an incorrect output and should be removed.
Example 3 [IO-UNIT]
The header is similar to the previous example
(stdout)->: This shows what your program should produce after each test case action.
If the IO-testing part of this test case fails, then you will see an additional output similar to [IO]
test cases shown in Example 2.If the unit-testing part of this test case fails, then you will see an additional output similar to
[UNIT] test cases shown in Example 1.Tips:
Sometimes the output of the cases in the diff view will not be helpful e.gThis will usually happen for IO-UNIT test cases. Switching to Your output view will be more helpful
in such cases.Music Wrapped (Part 1)
Write a program that verifies a user's username and password and displays the most
streamed song, artist, genre and total streaming hours for a specified month of a year. The
music wrapped will be displayed in a format specified in part 2.
This question involves knowledge from the following Ed Lessons (but not limited to):
IF statement
FOR loops
Break and continue
WHILE loops
Handling errors
Functions
Input/Output
In this part, we will ONLY focus on verifying user authentication.
Format of <username>.txt
The first line will always contain the password of the <username> . The rest of the lines contain the
details of the songs the user listens to each time. Each line will represent a single listening entry and
will be shown in the following format:
<password>
<song_name>,<artist>,<genre>,<song_duration>,<date>
<password> : The <username> 's password
<song_name> : The name of the song.
<artist> : The artist of the song
<genre> : The genre of the song
<song_duration> : The duration of the song, in the format mm:ss
<date> : The date the song was listened to, in the format DD-MM-YYYY
In this exercise, Music Wrapped you can assume that the format of the file <username>.txt is always
correct. All lines in the file will be case-sensitive.
Example of akali.txt
dowhat12kjk
Espresso,Sabrina Carpenter,Pop,04:22,23-02-2024
Ephemeral Dreamscape,Celestial Echoes,Rock,03:54,24-03-2024where the first line contains the password of the username akali and each of other lines contains
the single listening entry of username akali.
This example has also been given to you as part of the scaffold.
Part 1 - Username and Password
The program will begin by displaying the welcome message Welcome to USYD MUSIC! . It will then
continuously prompt the user for their username and password until a matching pair is found or 3
unsuccessful attempts have been made. The program will prompt for user's username and password
in the exact following format:
Welcome to USYD MUSIC!
Enter your username: <username>
Enter your password: <password>
where <username> and <password> are placeholder for user's input for username and password.
The function check_password(username, password) is implemented to check whether the input
<username> and <password> match those in the system. This function will first check whether
<username> exists in the USYD MUSIC system by checking the existence of <username>.txt in the
user_info directory (i.e folder).
If <username>.txt does not exist, the program will print No <username> found :(( , where
<username> is the user input, and returns False .
Otherwise, if <username>.txt exists, the program will check if the entered <password>
matches the password stored on the first line of the file.
If the password matches, print Login successful :)) and returns True .
Otherwise, print Username and password do not match :(( and return False .
If the function check_password returns True , exit the program. Otherwise, the program will go back
to prompt for the user's username and password. If the maximum number of 3 attempts has been
reached, the program will stop prompting for input and exit the program with the following message
Maximum of 3 attempts has been reached. You will be temporarily disabled from logginng
in :((
Example 1 - Matching Username and Password
$ python3 wrapped.py
Welcome to USYD MUSIC!
Enter your username: akali
Enter your password: dowhat12kjk
Login successful :))
Example 2 - Reaching 3 attempts$ python3 wrapped.py
Welcome to USYD MUSIC!
Enter your username: akali
Enter your password: dowhat12
Username and password do not match :((
Enter your username: aka
Enter your password: dowhat12kjk
No aka found :((
Enter your username: akali
Enter your password: idontknow
Username and password do not match :((
Maximum of 3 attempts has been reached. You will be temporarily disabled from logging in :((
Note: You can assume that all standard input are always valid. Lines that start with a $ indicates a
terminal command, which is an instruction you type into the terminal to run your program. Standard
inputs, which the user types into the terminal, are shown in bold.
Competency Requirements:
The test cases do not test that you meet all competency requirements. Please review the requirements
yourself even if you get a green tick. The green tick "mark" just checks if your code runs.
You can test your code as many times as you like before the submission deadline.Song Information
Write a Song class containing all song information and functionality relevant to the song.
This question involves knowledge from the following Ed Lessons (but not limited to):
Variables and data types
IF statements
CLASSES
The Song class will be used in all future exercises in Assignment Part B.
The program requires you to implement the Song class (including its attributes and methods) to store
all information on the songs and functionalities (i.e. methods) that are relevant to the Song objects.
Here are the instance attributes of a Song object.
Here are the instance methods of Song object.Competency Requirements:
The test cases do not test that you meet all competency requirements. Please review the requirements
yourself even if you get a green tick. The green tick "mark" just checks if your code runs.
You can test your code as many times as you like before the submission deadline.Music Wrapped (Part 2)
This question involves knowledge from the following Ed Lessons (but not limited to):
String formatting
IF statements
input() function
Containers (lists, tuples, and dictionaries
Mutable and Immutable data
WHILE and FOR loops
Handling errors
Functions
CLASSES
In this exercise, Music Wrapped, you can assume that the format of the file <username>.txt is always
correct. All lines in the file will be case-sensitive.
Write a program that verifies a user's username and password and displays the most
streamed song, artist, and genre within a specified month in a year. The music wrapped will
be displayed at the end of this part.
In this part, we will focus on creating the Music Wrapped Wall.
You will need to use the Song class in this exercise. You can just copy over the song.py file from the previous
exercise.
Part 2 - Wrapped Wall
The initial login part is the same as what you implemented in Part 1 and can be copied
over.
After a successful login, the program will ask for the specific with message Specify the month that
you want to display: . The input will be validated in the following order:
If the input is not an integer, print Month must be an integer :((
If the input is not within the range of , print Month must be between 1 and 12,
inclusively :((
[1, 12]
If the input is valid, the program will ask for the specific year with a message Specify the year
that you want to display: . The input will be validated in the following order:If the input is not an integer, print Year must be an integer :((
If the input is less than 2000, print Year must be larger than 2000 :((
You can assume that the user will not input a year larger than 2024.
Here we list the functions that you will implement and call within the main() function. Later we
provide details for each function.
You should be extracting the songs using the extract_song_details() function using the
username and the month and year provided by the user.
You should then use count_streams() with the extracted songs to find the number of times
each song, artist and genre has been listened to. Think about how the date_type parameters is
going to help you with that.
Once you have separate dictionaries for songs, artists and genres, you need to use the
find_most_frequent() function to find the most streamed song, artist and genre as tuples.
As you are also required to print the total streaming time, you need to use the
calculate_streaming_second() on the songs list to find the total streaming time in seconds.
Finally, you will pass the tuples and total streaming time to the print_rewind_wall() function
to print the final output.
extract_song_details()
Parameters:
filename: str : user file to extract songs from
month: int : month for which the songs need to be extracted from
year: int : year for which the songs need to be extracted from
Returns:
list[Song] : list of song objects extracted, each as a Song object
The first line will always contain the password of the <username> . The rest of the lines contain the
details of the songs the user listens to each time. Each line will represent a single listening entry and
will be shown in the following format:
<password>
<song_name>,<artist>,<genre>,<song_duration>,<date>
<password> : The <username> 's password
<song_name> : The name of the song.
<artist> : The artist of the song
<genre> : The genre of the song
<song_duration> : The duration of the song, in the format mm:ss
<date> : The date the song was listened to, in the format DD-MM-YYYYcount_streams()
Parameters:
songs: list[Song] : list of song objects
data_type: str : The song attribute for which we need the frequency. This will be either:
'song'
'artist'
'genre'
Returns:
dict[str: int] : A dictionary with the unique song, artist, or genre as keys and the
corresponding streaming counts as values. This should be in the format {song/genre/artist:
frequency, song/genre/artist: frequency,...} where
song/genre/artist is the name of a song, genre or artist depending on the data_type
parameter
frequency is how many times it appears in the songs list.
The count_streams() function will count the streaming frequency for each unique song, artist, or
genre (specified by the data_type parameter). The name of each unique song, artist, or genre will be
used as the key in the dictionary, while the number of streams will be stored as the value. During the
search, if the current song, artist, or genre is already in the dictionary, the streams count is
incremented by one.
You can assume that there will be at least one line for the specified month and year .
find_most_frequent()
Parameters:
streaming_data: dict[Song] : A dictionary containing the streaming data of a single
data_type
Returns:
tuple[str, int] : A tuple containing the key (song, artist, or genre) and its corresponding
number of streaming times.
The find_most_frequent() function will find the most frequently streamed song, artist, or genre.
This is done by iterating through a dictionary of song, artist, or genre data and identifying the keyvalue
pair with the largest streaming count. The function will return the key-value pair with the largest the streaming count as a tuple.
You can assume that there will be no ties.
calculate_streaming_seconds()
Parameters:
songs: list[Song] : list of song objects
Returns:
int : The total streaming seconds
The calculate_streaming_seconds() function will calculate the total streaming seconds from a list
of songs. This is done by iterating through all Song objects and adding their streaming time. This
function will return the total streaming seconds at the end.
print_wrapped_wall()
Parameters:
top_song: tuple(str, int) : the name of top song and its streaming frequency.
top_artist: tuple(str, int) : the name of top artist and its streaming frequency.
top_genre: tuple(str, int) : the name of top genre and its streaming frequency.
total_stream: int : the total streaming seconds
We will use the information about the total_streaming seconds and the most popular songs, artist
and genre within a specific time frame to display the Music Wrapped Wall. The function will first
display banner for the Wrapped Wall as follows:
****************************************************
MONTHLY MUSIC WRAPPED WALL
****************************************************
We then need to print the most streamed song, artist and genre in a specific format as follows:
Top Name Stream Times
Song <song_name> XXXX
Artist <artist_name> XXXX
Genre <genre_name> XXXX
Format specificationEach row will contain 3 columns: Top, Name, and Stream times.
Top : Left-padded with a column width of 8 characters.
Name : Left-padded with a column width of 32 characters.
Stream times : Displayed in a 4-digit format (XXXX) with leading zeros if necessary.
You can assume that all strings in the name column will be fewer than 31 characters long.
The function will then print the total listening hours as follows after converting it from seconds to
DD:HH:mm:ss .
****************************************************
Total streaming DD:HH:mm:ss
****************************************************
Remember to convert the seconds into days, hours, minutes and seconds in this function
Format Specifications:
Total streaming: Left-padded with a column width of 41 characters.
DD: Represents the number of whole streaming days with leading zeros.
HH: Represents the number of whole streaming hours with leading zeros.
mm: Represents the number of whole streaming minutes with leading zeros.
ss: Represents the number of streaming seconds with leading zeros.
You can assume that the stream times is a positive integer that less than 9999
Example of Monthly Wrapped
****************************************************
MONTHLY MUSIC WRAPPED WALL
****************************************************
Top Name Stream Times
Song Do you want to build a snowman 0020
Artist Elena Williams 0100
Genre Pop 0193
****************************************************
Total streaming DD:HH:mm:ss
End-to-end Examples
Sample 1 - akali$ python3 wrapped.py
Welcome to USYD MUSIC!
Enter your username: akali
Enter your password: dowhat12kjk
Login successful :))
Specify the month that you want to display: 2
Specify the year that you want to display: 2024
****************************************************
MONTHLY MUSIC WRAPPED WALL
****************************************************
Top Name Stream Times
Song Espresso 0002
Artist Sabrina Carpenter 0002
Genre Pop 0002
****************************************************
Total streaming 00:00:08:44
Sample 2 - karencat with invalid inputs
$ python3 wrapped.py
Welcome to USYD MUSIC!
Enter your username: karencat
Enter your password: password
Login successful :))
Specify the month that you want to display: ab
Month must be an integer :((
Specify the month that you want to display: 13
Month must be between 1 and 12, inclusively :((
Specify the month that you want to display: 6
Specify the year that you want to display: 6a
Year must be an integer :((
Specify the year that you want to display: 1999
Year must be larger than 2000 :((
Specify the year that you want to display: 2024
****************************************************
MONTHLY MUSIC WRAPPED WALL
****************************************************
Top Name Stream Times
Song Sunset Lover 0003
Artist The Weeknd 0004
Genre Pop 0004
****************************************************
Total streaming 00:00:32:59
These sample user files have been given to you as part of the scaffold.
Note: You can assume that all standard input are always valid. Lines that start with a $ indicates a
terminal command, which is an instruction you type into the terminal to run your program. Standard inputs, which the user types into the terminal, are shown in bold.
Competency Requirements:
The test cases do not test that you meet all competency requirements. Please review the requirements
yourself even if you get a green tick. The green tick "mark" just checks if your code runs.
You can test your code as many times as you like before the submission deadline.Song queues (Part 1)
Write a program that mimics the queue functionality of a music app. The program should
allow users to reset, append or modify existing queues and create a new queue. This task
will be divided into two parts.
The first part will focus on implementing a program that supports adding songs to the queue.
Just like the previous program, copy over your Song class to the song.py folder
This question involves knowledge from the following Ed Lessons (but not limited to):
String formatting
IF statements
input() function
Containers (lists, tuples, and dictionaries
Mutable and Immutable data
WHILE and FOR loops
Handling errors
Functions
CLASSES
You need to use add_song() and write_queue() functions that you will implement in the main()
function.
You need to first prompt the user for the queue mode. See Selecting the queue mode section
below
You then need to initialise an empty list as a queue.
You need to then get song inputs if a user is specified. See Getting song input section below
Here you will be checking whether the argument of <operation> is valid. If it is invalid,
print ***Invalid operation!*** and continue to prompt for next song input.
If a valid <operation> is provided, you should use load_song() function to help
initialise a Song object and add this to the queue using the add_song() function. The
songs will be added to the queue you initialised in point 2.
After the user enters END QUEUE , you will pass the final queue i.e the list of Song objects to
write_queue() function to write all songs in the queue into the <username>_queue.txt file in
the queue_info directory.
1. Selecting the queue mode
The program will receive the username of the users via command line arguments. If no command line argument are given, print No username found! and exit the programs. Otherwise, the program
will check for the existence of <username> 's queue by searching for <username>_queue.txt in the
queue_info directory.
If the <username>_queue.txt file does not exist:
The program will display No queue for <username> found! Creating a new queue...
and then prompt the user for song inputs. In this case, you will need to set the queue
mode to CREATE when calling the write_queue() function later (see below).
Otherwise, the program will ask the user to select between RESET or APPEND mode with the
message Do you want to reset or append to your queue?
If the user inputs RESET , the program will display Resetting your queue... and then
prompt the user for song inputs. You need to set the queue mode to RESET when calling
the write_queue() function to overwrite the file with the queue.
If the user inputs APPEND , the program will display Appending to your queue... . You
need to set the queue mode to APPEND when calling the write_queue() function to
write the queue below the existing queue in the file
If the user inputs neither of the above, the program will print Invalid mode! and return
to prompt for the queue mode.
The input for this prompt will be case-insensitive but space-sensitive (i.e., no leading or trailing
whitespace before or after the input).
Have a look at END-TO-END Examples at the bottom for examples.
2. Getting song input
The program will display a message Update songs in the queue: and ask the user to update the
queue via standard input. The user is expected to provide the details of the song exactly as specified
below:
<operation>,<song name>,<artist>,<genre>,<duration>
<operation> : specify whether the user wants to add ( A ) or not. operations are case sensitive,
meaning 'a' would be an invalid operation.
A : The program calls add_song() function to add song into the playlist.
Otherwise, prints ***Invalid operation!***
<song name> : The name of the song, with words.
<artist> : The name of the artist who sings the song.
<genre> : The genre of the song.
<duration> : The song duration in the format mm:ss .
Each argument will be separated by a comma , .
If the user inputs END QUEUE (case sensitive) , stop prompting the user and write the songs in the queue to the file.
You can assume that all song inputs are always in a correct format.
Have a look at END-TO-END Examples at the bottom for examples.
load_song_from_input()
Parameters:
input_song: str : The string that contains the song information in a correct format. This will
be the input given by the user in the form <operation>,<song name>,<artist>,<genre>,
<duration>
Returns:
Song : The Song object created using the information provided in the parameter.
The load_song_from_input() function parses the input song and extract all song's information. This
information is used to initialise a Song object.
add_song()
Parameters:
queue: list[Song] : list of Song objects
song: Song : The Song object to be added to the queue.
The add_song() function adds a song to the queue (called when the user input has value A in the
<operation> field). If a Song object with the same name and artist already exists in the queue, the
program will print ***'<song name>' by <artist> is already in the queue*** . You only need
to check this against the songs that are being input by the user NOT what exists in the file.
You can assume a user would not add a song to the queue that exists in the file.
Otherwise, the program will print ***'<song_name>' by <artist> is added to the queue*** and
add this Song object to the queue variable.
Think about why we do not need to return the queue to update the queue variable in the main function write_queue()
Parameters:
filename: str : file to wrote the queue into.
queue: list[Song] : list of Song objects in the queue
queue_mode: str : The queue mode selected in "Selecting the queue mode" section. The queue
mode is either RESET, APPEND or CREATE
The write_queue() function writes all Song objects stored in the queue variable to the
<username>_queue.txt file in the queue_info directory. The file-open mode depends on the
selected queue mode:
CREATE: Create a new file to store the queue information and write the queue to it.
RESET: Overwrite the contents of the <username>_queue.txt file with the new queue.
APPEND: Write the new queue below the old queue in the <username>_queue.txt file.
Each song in the queue is written as a single line in the output file. The format of each line is as
follows:
<song name>,<artist>,<genre>,<song duration>
<song name> : The name of the song.
<artist> : The artist of the song.
<genre> : The genre of the song.
<song duration> : The duration of the song in the format mm:ss
Example of the output file karencat_queue.txt
Espresso,Sabrina Carpenter,Pop,04:22
Ephemeral Dreamscape,Celestial Echoes,Rock,03:54
END-TO-END Examples
Example 1 - No command line argument given
Terminal output
$python3 queue.py
No <username> found!
Example 2 - Queue does not exist: Createkarencat_queue.txt does not exist before the program is run
Terminal output
$python3 queue.py karencat
No queue for karencat found! Creating a new queue...
Update songs in the queue: A,Magnificient,Sasha Scarlet,Pop,04:23
***'Magnificient' by Sasha Scarlet is added to the queue***
Update songs in the queue: A,Twinkle star,Layla Smiths,Kids,02:22
***'Twinkle star' by Layla Smiths is added to the queue***
Update songs in the queue: A,Magnificient,Sasha Scarlet,Pop,04:23
***'Magnificient' by Sasha Scarlet is already in the queue***
Update songs in the queue: X,Magnificient,Sasha Scarlet,Pop,04:23
***Invalid operation!***
Update songs in the queue: END QUEUE
karencat_queue.txt will be created after the program is run
Magnificient,Sasha Scarlet,Pop,04:23
Twinkle star,Layla Smiths,Kids,02:22
Example 3 - Queue already exists: Append
karencat_queue.txt before the program is run
Espresso,Sabrina Carpenter,Pop,04:22
Ephemeral Dreamscape,Celestial Echoes,Rock,03:54
Terminal output
$python3 queue.py karencat
Do you want to reset or append to your queue? ApPEnD
Invalid mode!
Do you want to reset or append to your queue? APPED
Invalid mode!
Do you want to reset or append to your queue? aPPeND
Appending to your queue...
Update songs in the queue: A,Magnificient,Sasha Scarlet,Pop,04:23
***'Magnificient' by Sasha Scarlet is added to the queue***
Update songs in the queue: A,Twinkle star,Layla Smiths,Kids,02:22
***'Twinkle star' by Layla Smiths is added to the queue***Update songs in the queue: A,Magnificient,Sasha Scarlet,Pop,04:23
***'Magnificient' by Sasha Scarlet is already in the queue***
Update songs in the queue: X,Magnificient,Sasha Scarlet,Pop,04:23
***Invalid operation!***
Update songs in the queue: END QUEUE
karencat_queue.txt after the program is run
Espresso,Sabrina Carpenter,Pop,04:22
Ephemeral Dreamscape,Celestial Echoes,Rock,03:54
Magnificient,Sasha Scarlet,Pop,04:23
Twinkle star,Layla Smiths,Kids,02:22
Example 4 - Queue already exists: Reset
karencat_queue.txt before the program is run
Espresso,Sabrina Carpenter,Pop,04:22
Ephemeral Dreamscape,Celestial Echoes,Rock,03:54
Terminal output
$python3 queue.py karencat
Do you want to reset or append to your queue? RESET
Resetting your queue...
Update songs in the queue: A,Magnificient,Sasha Scarlet,Pop,04:23
***'Magnificient' by Sasha Scarlet is added to the queue***
Update songs in the queue: A,Twinkle star,Layla Smiths,Kids,02:22
***'Twinkle star' by Layla Smiths is added to the queue***
Update songs in the queue: A,Magnificient,Sasha Scarlet,Pop,04:23
***'Magnificient' by Sasha Scarlet is already in the queue***
Update songs in the queue: X,Magnificient,Sasha Scarlet,Pop,04:23
***Invalid operation!***
Update songs in the queue: END QUEUE
karencat_queue.txt after the program is run
Magnificient,Sasha Scarlet,Pop,04:23
Twinkle star,Layla Smiths,Kids,02:22
Note: You can assume that all standard input are always valid. Lines that start with a $ indicates a terminal command, which is an instruction you type into the terminal to run your program. Standard
inputs, which the user types into the terminal, are shown in bold.
This means you can assume the user will:
Always provide correct number of arguments when adding the song to the queue
Will provide the correct arguments for the song
Competency Requirements:
The test cases do not test that you meet all competency requirements. Please review the requirements
yourself even if you get a green tick. The green tick "mark" just checks if your code runs.
You can test your code as many times as you like before the submission deadline.Song queues (Part 2)
Write a program that mimics the queue functionality of a music app. The program should
allow users to reset, append or modify existing queues and create a new queue.
This is the second part of song queues where you will focus on implementing features that allow users
to remove songs and replace songs in a specific position in the queue.
You can copy over functions that you have already implemented from the previous parts
This question involves knowledge from the following Ed Lessons (but not limited to):
String formatting
IF statements
input() function
Containers (lists, tuples, and dictionaries)
Mutable and Immutable data
WHILE and FOR loops
Handling errors
Functions
CLASSES
You need to use all functions in part 1 and additional replace_song() and remove_song()
functions in this task in the main() function. Here we list high-level functionality, and later we
provide detailed specifications for each function.
As carries on from part 1, your program will still receive the username of the users via
command line arguments. If no command line arguments are given, print No username
found! and exit the programs.
After that, your program should prompt user to select the queue mode until receive a valid
input as stated in the first part.
You then need to initialise an empty list as a queue (Similar to part 1).
After successfully selecting the queue mode, your program should prompt for song input until
the user enter END QUEUE . The format input of song is exactly the same as stated in part 1,
except your program should also handle ( R ) remove and ( S ) replace as other argument options
for <operation> .
If the <operation> is R , you should be removing a song from the queue using the
remove_song() function.
If the <operation> is S , you should ask for the position of the song they want to replace with the message: Which position do you want to replace this song with? . You
should then be replacing a target song in the queue with the replacement song specified
via input using the replace_song() function.
Your program continue prompt, and then add/remove/replace until the user enters END QUEUE .
You then pass the list of Song objects to write_queue() function to write all songs in the
queue into the <username>_queue.txt file.
remove_song()
Parameters:
queue: list[Song] : list of Song objects
song: Song : The Song object to be removed from the queue.
The remove_song() function removes a specified song from the queue if the user inputs R for
<operation> .This function iterates through a list of Song objects to find the Song object that
matches the name and artist of the input. If no Song objects in the queue match these, prints ***No
'<song_name>' by <artist> found, cannot remove it*** . Otherwise, prints ***Successfully
removed '<song_name>' by <artist>*** .
If the queue mode is APPEND , you cannot remove song details that have already been written to the output
file. You can only remove songs that the user inputs in.
replace_song()
Parameters:
queue: list[Song] : list of Song objects
song: Song : The Song object to be moved into the queue.
position: str : The position of the song to be replaced in zero base-indexing given by the
user.
The replace_song() function replaces a specified song with another at a specified position. This
function will check if the input position is valid. If the specified position is valid, prints
***Successfully replaced '<song_name1>' by <artist1> to '<song_name2>' by <artist2>*** ,
where <song_name1> and <artist1> are the name and artist of the input song and <song_name2>
and <artist2> are the name and artist of the song that got replaced. The song that gets replaced will
be removed from the queue.
Otherwise, the replace operation will not occur, and a corresponding error message will be printed.
The order of error checking is as follows:
Not an integer: Prints ***Position must be an integer***
Negative integer: Prints ***Position must be at least 0***
Out of range of the queue: Prints ***The specified position is out of range of the queue***
If the queue mode is APPEND , you cannot replace song details that have already been written to the output
file. You can only replace with the songs that the user inputs in.
END-TO-END Examples
Example 1 - Create mode with Remove and Add operations
karencat_queue.txt does not exist before the program is run
Terminal output
$python3 queue.py karencat
No queue for karencat found! Creating a new queue...
Update songs in the queue: A,Magnificient,Sasha Scarlet,Pop,04:23
***'Magnificient' by Sasha Scarlet is added to the queue***
Update songs in the queue: A,Twinkle star,Layla Smiths,Kids,02:22
***'Twinkle star' by Layla Smiths is added to the queue***
Update songs in the queue: A,Magnificient,Sasha Scarlet,Pop,04:23
***'Magnificient' by Sasha Scarlet is already in the queue***
Update songs in the queue: X,Magnificient,Sasha Scarlet,Pop,04:23
***Invalid operation!***
Update songs in the queue: R,Magnificient,Sasha Scarlet,Pop,04:23
***Successfully removed 'Magnificient' by Sasha Scarlet***
Update songs in the queue: R,Magnetic,Hyper,KPop,04:23
***No 'Magnetic' by Hyper found, cannot remove it***
Update songs in the queue: R,Magnificient,Sasha Scarlet,Pop,04:23
***No 'Magnificient' by Sasha Scarlet found, cannot remove it***
Update songs in the queue: END QUEUE
karencat_queue.txt will be created after the program is run
Twinkle star,Layla Smiths,Kids,02:22
Example 2 - Append mode with Remove and Add operations
karencat_queue.txt before the program is runEspresso,Sabrina Carpenter,Pop,04:22
Ephemeral Dreamscape,Celestial Echoes,Rock,03:54
Terminal output
$python3 queue.py karencat
Do you want to reset or append to your queue? ApPEnD
Invalid mode!
Do you want to reset or append to your queue? APPED
Invalid mode!
Do you want to reset or append to your queue? aPPeND
Appending to your queue...
Update songs in the queue: A,Magnificient,Sasha Scarlet,Pop,04:23
***'Magnificient' by Sasha Scarlet is added to the queue***
Update songs in the queue: A,Twinkle star,Layla Smiths,Kids,02:22
***'Twinkle star' by Layla Smiths is added to the queue***
Update songs in the queue: A,Magnificient,Sasha Scarlet,Pop,04:23
***'Magnificient' by Sasha Scarlet is already in the queue***
Update songs in the queue: A,Beauty and the beast,Alena,Ballad,06:17
***'Beauty and the beast' by Alena is added to the queue***
Update songs in the queue: R,Do you want to build a snowman?,Elsa,Kids,03:14
***No 'Do you want to build a snowman?' by Elsa found, cannot remove it***
Update songs in the queue: R,Magnificient,Sasha Scarlet,Pop,04:23
***Successfully removed 'Magnificient' by Sasha Scarlet***
Update songs in the queue: END QUEUE
karencat_queue.txt after the program is run
Espresso,Sabrina Carpenter,Pop,04:22
Ephemeral Dreamscape,Celestial Echoes,Rock,03:54
Twinkle star,Layla Smiths,Kids,02:22
Beauty and the beast,Alena,Ballad,06:17
Example 3 - Create mode with Add and replace operations
karencat_queue.txt does not exist before the program is run
Terminal output
$python3 queue.py karencat
No queue for karencat found! Creating a new queue...Update songs in the queue: A,Magnificient,Sasha Scarlet,Pop,04:23
***'Magnificient' by Sasha Scarlet is added to the queue***
Update songs in the queue: A,Twinkle star,Layla Smiths,Kids,02:22
***'Twinkle star' by Layla Smiths is added to the queue***
Update songs in the queue: A,Magnificient,Sasha Scarlet,Pop,04:23
***'Magnificient' by Sasha Scarlet is already in the queue***
Update songs in the queue: X,Magnificient,Sasha Scarlet,Pop,04:23
***Invalid operation!***
Update songs in the queue: A,Beauty and the beast,Alena,Ballad,06:17
***'Beauty and the beast' by Alena is added to the queue***
Update songs in the queue: S,Magnetic,Hyper,KPop,04:23
Which position do you want to replace this song with? 1
***Successfully replaced 'Twinkle star' by Layla Smiths to 'Magnetic' by Hyper***
Update songs in the queue: S,All by me,Jasper,KPop,05:34
Which position do you want to replace this song with? 10
***The specified position is out of range of the queue***
Update songs in the queue: S,All by me,Jasper,KPop,02:34
Which position do you want to replace this song with? ten
***Position must be an integer***
Update songs in the queue: S,All by me,Jasper,KPop,05:22
Which position do you want to replace this song with? -10
***Position must be at least 0***
Update songs in the queue: END QUEUE
karencat_queue.txt will be created after the program is run
Magnificient,Sasha Scarlet,Pop,04:23
Magnetic,Hyper,KPop,04:23
Beauty and the beast,Alena,Ballad,06:17
Example 4 - Append mode with replace and Add operations
karencat_queue.txt before the program is run
Espresso,Sabrina Carpenter,Pop,04:22
Ephemeral Dreamscape,Celestial Echoes,Rock,03:54
Terminal output
$python3 queue.py karencat
Do you want to reset or append to your queue? AppendAppending to your queue...
Update songs in the queue: A,Magnificient,Sasha Scarlet,Pop,04:23
***'Magnificient' by Sasha Scarlet is added to the queue***
Update songs in the queue: A,Twinkle star,Layla Smiths,Kids,02:22
***'Twinkle star' by Layla Smiths is added to the queue***
Update songs in the queue: A,Magnificient,Sasha Scarlet,Pop,04:23
***'Magnificient' by Sasha Scarlet is already in the queue***
Update songs in the queue: X,Magnificient,Sasha Scarlet,Pop,04:23
***Invalid operation!***
Update songs in the queue: A,Beauty and the beast,Alena,Ballad,06:17
***'Beauty and the beast' by Alena is added to the queue***
Update songs in the queue: S,Magnetic,Hyper,KPop,04:23
Which position do you want to replace this song with? 1
***Successfully replaced 'Twinkle star' by Layla Smiths to 'Magnetic' by Hyper***
Update songs in the queue: S,All by me,Jasper,KPop,05:34
Which position do you want to replace this song with? 10
***The specified position is out of range of the queue***
Update songs in the queue: S,All by me,Jasper,KPop,02:34
Which position do you want to replace this song with? ten
***Position must be an integer***
Update songs in the queue: S,All by me,Jasper,KPop,05:22
Which position do you want to replace this song with? -10
***Position must be at least 0***
Update songs in the queue: END QUEUE
karencat_queue.txt after the program is run
Espresso,Sabrina Carpenter,Pop,04:22
Ephemeral Dreamscape,Celestial Echoes,Rock,03:54
Magnificient,Sasha Scarlet,Pop,04:23
Magnetic,Hyper,KPop,04:23
Beauty and the beast,Alena,Ballad,06:17
Example 5 - Reset with all operations
karencat_queue.txt before the program is run
Espresso,Sabrina Carpenter,Pop,04:22
Ephemeral Dreamscape,Celestial Echoes,Rock,03:54Terminal output
$python3 queue.py karencat
Do you want to reset or append to your queue? reset
Resetting your queue...
Update songs in the queue: A,Magnificient,Sasha Scarlet,Pop,04:23
***'Magnificient' by Sasha Scarlet is added to the queue***
Update songs in the queue: A,Twinkle star,Layla Smiths,Kids,02:22
***'Twinkle star' by Layla Smiths is added to the queue***
Update songs in the queue: A,Magnificient,Sasha Scarlet,Pop,04:23
***'Magnificient' by Sasha Scarlet is already in the queue***
Update songs in the queue: A,Beauty and the beast,Alena,Ballad,06:17
***'Beauty and the beast' by Alena is added to the queue***
Update songs in the queue: R,Do you want to build a snowman?,Elsa,Kids,03:14
***No 'Do you want to build a snowman?' by Elsa found, cannot remove it***
Update songs in the queue: R,Magnificient,Sasha Scarlet,Pop,04:23
***Successfully removed 'Magnificient' by Sasha Scarlet***
Update songs in the queue: S,Starlight,Bobby,Pop,05:12
Which position do you want to replace this song with? 0
***Successfully replaced 'Twinkle star' by Layla Smiths to 'Starlight' by Bobby***
Update songs in the queue: END QUEUE
Output file karencat_queue.txt
Starlight,Bobby,Pop,05:12
Beauty and the beast,Alena,Ballad,06:17
Note: You can assume that all standard input are always valid. Lines that start with a $ indicates a
terminal command, which is an instruction you type into the terminal to run your program. Standard
inputs, which the user types into the terminal, are shown in bold.
Competency Requirements:
The test cases do not test that you meet all competency requirements. Please review the requirements
yourself even if you get a green tick. The green tick "mark" just checks if your code runs.
You can test your code as many times as you like before the submission deadline.Log of Changes
The changes will only contain reclarifications of description and inconsistencies in the docstring / type-hints.
We aim to have no changes to the actual code implementation.
The changes as of now is simply miscellaneous and very small. It would be faster to just copy and paste it over.
However, you may also click the ... and click Reset to Scaffold which will give you an up to date scaffold.
Ensure you first submit your code before resetting to scaffold with this so you can copy all your
implementation back over.
Extra Pinned Changes
Pinned Changes
20/09
3:20pm:
Changed the name of testcase "[Song] is_identical True and False (UNIT)" to "[Song] is_same True and
False (UNIT)" and fixed its bugs.
2:00pm:
Fixed the docstring for the parameter song of the function replace_song() , from "removed from"
to "moved into".
16/09
10:20am
Fixed the scaffold for song.py to fix misspelled method names and missing methods for exercises
after Song Informatiion. Please copy over your solution from Song Information to the song.py
files in the rest of the exercises.
10/09
6:00pm
The format specification of Top for print_wrapped_wall() in Music Wrapped (Part 2) was changed
from 6 characters to 8 characters to match the expected output for the test cases.3:00pm
The scaffold for Song.py was updated for all Song Queues to fix the constructor. Please copy over
your song.py file from previous exercises or just reset to scaffold to pull latest changes.
The condition in Song Queues (Part 1) if __name__ == '__main__' was fixed to include == instead
of = . You can fix this or just reset to scaffold to pull latest changes.
12:15pm
The scaffold for queue.py was updated for Song Queues (Part 2) to change the swap_song()
method to replace_song() as specified in the question description. Please rename the method to
pass test cases or just reset to scaffold to pull latest changes.
10:30am
The example and test cases were fixed to correct the spelling of logging .
$ python3 wrapped.py
Welcome to USYD MUSIC!
Enter your username: akali
Enter your password: dowhat12
Username and password do not match :((
Enter your username: aka
Enter your password: dowhat12kjk
No aka found :((
Enter your username: akali
Enter your password: idontknow
Username and password do not match :((
Maximum of 3 attempts has been reached. You will be temporarily disabled from logging in :((
09/09
10:30pm
The example snippets for print_wrapped_wall() had extra whitespaces after Stream Times for first
song and the test case was expecting 'MONTHLY MUSIC REWIND WALL' instead of 'MONTHLY MUSIC
WRAPPED WALL'. The examples and the test cases have now been fixed, please refresh the page to
remark and resubmit.
****************************************************
MONTHLY MUSIC WRAPPED WALL
****************************************************
Top Name Stream Times
Song Do you want to build a snowman 0020
Artist Elena Williams 0100Genre Pop 0193
****************************************************
Total streaming DD:HH:mm:ss
3:30pm
The scaffold for Song.py was updated for all exercises to change the has_same_duration() method
to get_longest() as specified in the question description. Please rename the method to pass test
cases or just reset to scaffold to pull latest changes.Code Review - In Week 9 Lab
Do not forget to turn up for your code review in the Week 9 Lab.
If you are unable to attend, you will need to apply for special consideration. For more details on the
special consideration process and instructions on how to apply -
https://canvas.sydney.edu.au/courses/59287/pages/special-consideration?module_item_id=2468718
版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。