首页 > > 详细

代写data编程、代做python程序设计

项目预算:   开发周期:  发布时间:   要求地区:
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.
############## ############# 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 .txt
The first line will always contain the password of the . 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:

,,,,
: The 's password
: The name of the song.
: The artist of the song
: The genre of the song
: The duration of the song, in the format mm:ss
: 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 .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:
Enter your password:
where and are placeholder for user's input for username and password.
The function check_password(username, password) is implemented to check whether the input
and match those in the system. This function will first check whether
exists in the USYD MUSIC system by checking the existence of .txt in the
user_info directory (i.e folder).
If .txt does not exist, the program will print No found :(( , where
is the user input, and returns False .
Otherwise, if .txt exists, the program will check if the entered
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 .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 . 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:

,,,,
: The 's password
: The name of the song.
: The artist of the song
: The genre of the song
: The duration of the song, in the format mm:ss
: 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 XXXX
Artist XXXX
Genre 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 is valid. If it is invalid,
print ***Invalid operation!*** and continue to prompt for next song input.
If a valid 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 _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 's queue by searching for _queue.txt in the
queue_info directory.
If the _queue.txt file does not exist:
The program will display No queue for 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:
,,,,
: 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!***
: The name of the song, with words.
: The name of the artist who sings the song.
: The genre of the song.
: 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 ,,,,

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
field). If a Song object with the same name and artist already exists in the queue, the
program will print ***'' by 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 ***'' by 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
_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 _queue.txt file with the new queue.
APPEND: Write the new queue below the old queue in the _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:
,,,
: The name of the song.
: The artist of the song.
: The genre of the song.
: 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 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.
软件开发、广告设计客服
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 9951568
© 2021 www.rj363.com
软件定制开发网!