Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

CSE 231

Spring 2022

Programming Project #6

Assignment Overview

In this assignment, you will practice with lists.


Background

Billboard is an American music and entertainment magazine published weekly since its founding in 1894, that is 128 years ago—quite a run. For nearly 100 years they have made a list ofthe 100 top songs in the US, currently  called “The Hot 100” with Adele’s “Easy on Me” the top song as this is being written.  We downloaded their top 100 songs into a CSV file for this project; the first file was from around Christmas which is why you see              Christmas songs in the list; the second file was in mid-January.  You will read the file, putting each song into a    list, and appending each song list into a master_list of songs, i.e. a master list of one hundred song lists. Link:

https://www.billboard.com/charts/hot-100/


Requirements:

1.   You will write a program that reads a CSV file, puts the data into a master list of lists, and has some functions that will manipulate that master_list.  There will be a main program that loops,          prompting the user for choices.

2.   You have to use the 10 functions plus main() in the provided proj06.py skeleton. We also provide a strings.txt file which contains all the strings that your need for the input and print statements to  match Mimir tests. You have to implement and use them as specified:

a.    get_option(): str

i.   Prompt the user for a valid option and return it as a string. If an invalid option is input,    an error message is displayed, and the user is re-prompted until a valid one is input. The user input can be input as upper or lowercase, but it should be converted to lowercase     before being returned.  See the provided proj06.py skeleton and the strings.txt file for prompts and error message strings. A valid input should be a, b, c, d, or q

ii. Parameters: none

iii.   Returns: str

iv.   Displays: prompts & error messages

b.   open_file() file pointer

i.   Prompts for a file name and continues to prompt until a file is correctly opened. See the provided strings.txt file for prompts and error message strings.  Hint: use try-  except.

ii.   Parameters: none

iii.   Returns: file pointer

iv.   Displays: prompts & error messages

c.    read_file(fp) list of lists

i.   Read the file referenced by the parameter.  Use the csv module’s reader method—    see notes. Remember to skip the header line, hint: next(reader,None). Each line  ofthe file is a song; put the song’s information into a list and then append that list   to your master list (remember to initialize the master list to empty before the loop).  The

song list is formatted this way – the same order as the file columns

[song, artist, rank, last_week, peak, weeks]

where song and artist are strings and the remaining four values are int.              For the int values, if the file entry is not a valid integer, use a -1 for its value. Hint: use try-except

Open the provided csv file in a spreadsheet such as Excel to observe what the fill looks like.

The list returned should be sorted by rank (which is the order they appear in the file so normally you shouldn’t have to sort it—only ifyou did something unusual in                 constructing your list).

ii.   Parameters: file pointer

iii.   Returns: sorted list of lists (specifically a master list of song lists)

iv.   Displays: nothing

d.   print_data(song_lst) nothing

i. Provided.  Prints a list of lists. Do not change this function. It is provided for you. You will use it later in your main function to print the data.

ii.   Parameters: list of list

iii.   Returns: nothing

iv.   Displays: formatted data

e.    get_christmas_songs(master_list) list of lists

i.   Selects songs from the master list; places the songs in a new list; returns the list. Selection is based on whether the song title has a Christmas theme.  The

constant CHRISTMAS_WORDS is provided in the skeleton file proj06.py.  Ifany of  those words appear in a song’s title, append that song’s entire list to the new list to be     returned. Remember that capitalization does not matter when checking when a word       appears in the song title.  Sort the returned list alphabetically by song titles (by default a list is sorted by its first element which is the song’s title; also by default it sorts                alphabetically).

ii.   Parameters: list of list

iii.   Returns: sorted list of list

iv.   Displays: nothing

f.    sort_by_peak(master_list) list of lists

i.   This function returns a sorted version of the given master_list organized by the peak rank, the value in the 5th column (index 4), WITHOUT MODIFYING THE       ORIGINAL LIST.  Sort in increasing order. Do not include a song if its peak rank    value is - 1. (Challenge: this can be done in one line.)

ii.   Parameters: list of list

iii.   Returns: sorted list of list

iv.   Displays: nothing

g.    sort_by_weeks_on_list(master_list) list of lists

i.   This function returns a sorted version of the given master_list organized by the      weeks on the top 100, the value in the 6th column (index 5), WITHOUT MODIFYING  THE ORIGINAL LIST. Sort in decreasing order. Do not include a song if its weeks on the list value is - 1. This function is nearly identical to sort_by_peak.

ii.   Parameters: list of list

iii.   Returns: sorted list of list

iv.   Displays: nothing

h.    Song_score(song) float

i.   Everyone has an idea of how to rank items such as these songs.  In order to rank items each needs a value to sort on.  Many techniques labeled as artificial intelligence (AI) are techniques to create values to rank items—using AI to adjust coefficients such as the       A, B, C, and D used in this function.  We assign those coefficients values as                constants at the top ofthe program.  The formula is score = A * peak_rank + B * rank_delta + C*weeks_on_chart

+ D*curr_rank

where

curr_rank is the current rank reversed. It means that the current number one song     has a curr_rank of 99 and the last song (the current song at 100) will have                curr_rank of 0.  However, if a song does not have a data entry for current rank (the  indicator of no value is - 1, which means that current rank is - 1) , curr_rank will be

-100.

peak_rank is similar to curr_rank except that we will be using the peak rank instead of current rank.

rank_delta is the change in rank from last week, e.g. ifthis week’s rank is 7 and last week’s rank was 2, rank_delta will be 5.

weeks_on_chart is simply the song’s weeks_on_chart value.              The coefficients A, B, C, and D are floats provided in the starter code.

ii.   Parameters: song (list)

iii.   Returns: float

iv.   Displays: nothing

i.     sort_by_score(master_list) list of lists

i.   This function returns a sorted version of the given master_list ranked by the value  returned by the score_song function in descending order (highest score to the             lowest) WITHOUT MODIFYING THE ORIGINAL LIST. Ifthere is a tie, sort by song name in reverse order. Hint: this function will call the score_song function for each  song to get the score.

ii.   Parameters: list of list

iii.   Returns: sorted list of list

iv.   Displays: nothing

j.    main():

i.   It’s the main driver ofthe program. It doesn’t have any parameters. It opens and reads a file and then it calls the other functions in a loop. Using get_option it gets an option that indicates which function to call.

ii.   Here is the basic structure.

1.   Display the heading  'Billboard Top 100'. The correct string format is in the  string.txt file .

2.    Open and read a file into a master_list, a list of lists.

3.   Display the initial data by calling the print_data function.

4.   Use get_option to prompt for an input character. Remember that the get_option function returns lower case version ofthe option.

5.   while not  'Q' or  'q' loop:

call each appropriate function and display by calling the print_data function. Note that the messages are given in the strings.txt:

a.    if the option is ‘a’ then display Christmas songs by calling

print_data function;

then, display the percentage of songs that are Christmas songs as integer using the following format:

'\n{:d}% of the top 100 songs are Christmas songs.' if none, print:

'\n Thanks for using this program!\nHave a good day!' 3.   Use Coding Standard 1-8

Deliverables

The deliverable for this assignment is the following file:

proj06.py -- your source code solution

Be sure to use the specified file name and to submit it for grading via Mimir before the project deadline.

Getting Started

Solve the problem using pencil andpaperfirst. You cannot write a program until you have     figured out how to solve the problem.  This first step can be done collaboratively with another student.  Talk through each function and what it does. However, once the discussion turns to   Python specifics and the subsequent writing ofPython, you must work on your own.

•    Use Anaconda Spyder to open the provided file (proj06.py).

•    Write a simple version ofthe program, e.g. open, read the file, and print it so you can test on your own Spyder.

•    Use the Mimir system to turn in the first version ofyour program.  The tests are written so that ifyou start with the code we provide, functions will be tested individually.

•    Next work on another function.  The get_option is the easiest;  get_christmas_songs is the hardest.

•    Cycle through the steps to incrementally develop your program:

o Edit your program to add new capabilities.

•    Use the Mimir system to submit your final version.