0% found this document useful (0 votes)
69 views5 pages

Python Music News Program Guide

The document provides instructions for a programming task to create a program that generates a short news item about a band's new track. It involves prompting the user for information like the band name, track name, streaming play counts and outputting a formatted message with the input details.

Uploaded by

Mohit Computer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views5 pages

Python Music News Program Guide

The document provides instructions for a programming task to create a program that generates a short news item about a band's new track. It involves prompting the user for information like the band name, track name, streaming play counts and outputting a formatted message with the input details.

Uploaded by

Mohit Computer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

PP Task 3.

2 Fill in the Blanks


Overview
Purpose: Learn how to declare variables, assign them
values, use them in expressions and format a
message to the user
Task: Follow the instructions to create a short news
item generation program. Submit to MyLO
when complete.
Learning Outcomes: 2, 3
Time: Complete during your tutorial and submit for
feedback before the start of Week 4.
Resources: ● Background Reading: Basic I/O (below)
● Concept Videos:
○ Programming Basics:
■ Working with Data
■ Using Library Code

Submission Details
Upload the following to the MyLO submission folder for this task:
● Your [Link] source file
● A screenshot showing the execution of your program

Assessment Criteria
A Completed submission will:
● Prompt for and read the required details from the user
● Output the message according to the given template
● Follow the unit’s coding style for layout, variable names, and commenting (including your
name at the top)
● Include a screenshot showing that it works
● Have the appropriate variables and use them appropriately

Background Reading: Basic I/O


While most or all of the programs you use in your day-to-day life have a graphical user interface
(GUI), the programs you create in this unit will have text-based interfaces, involving written user
input and formatted output by the program. Although this may seem archaic, it simplifies what
you need to learn, and the concepts of ‘getting information from the user’ and ‘presenting
information to the user’ are still relevant when you shift to building applications with a GUI.
The relevant Python functions for text-based interaction with the user are print(), input(), int()
and float():
● print("") displays text on the screen. There are three common forms you will use:
○ print("single string literal") displays the text inside the quotes, as in
single string literal
○ print("mix", "of", "values", var) combines the values it is given into a single string
with spaces between them (doing any necessary conversion of non-strings to text
that looks like their value) and then display it. So, if var = 42 then that command
would produce:
mix of values 42
○ print(f"formatted {string}") which uses the f-string to produce a formatted string
made up of fixed pieces of text and nested expressions, such as variables. This is
the most common form you will use to display information produced by your
program. In this example, if earlier we had string = "text" then this would produce:
formatted text
Tip: f-strings can be used anywhere in your program where you need to construct a
string that includes other data (variables or expressions)
● input("prompt to the user") asks the user for some input. It prompts them with the
text you provide (tip: that text could be an f-string if you need to customise it) and reads
the line of text they type in. It is almost always used in a variable assignment, as in:
name = input("Enter your name: ")
print(f"Hello {name}")
which, when run, with the user typing Arthur, looks like
Enter your name: Arthur
Hello Arthur
● Type conversion: Because input() always returns a string if you require a numerical
value then you will need to convert its result. The functions int() and float() can be
wrapped around call to input() to parse (that is, interpret) the text the user types as an
integer or real number. For example, the code:
stars = int(input("Enter a movie rating (1-5): "))
length = float(input("Movie length in hours (e.g., 2.3)? "))
print(f"You rated that {length} hour movie {stars} stars")
produces the following result, if the user were to type 5 and 1.52 at the prompts:
Enter a movie rating (1-5): 5
Movie length in hours (e.g., 2.3)? 1.52
You rated that 1.52 hour movie 5 stars
Over time you will see variations in how you can use both print() and f-strings to achieve more
advanced effects.

Instructions
Music is an important part of many people’s lives, and modern streaming services have paved
the way for extensive catalogues of millions of songs — Spotify, for example, claims over 100
million — to be available at the click (or tap) of a button. Whilst the era of online streaming has
not completely replaced physcial media, it does make it easier than ever to discover new music.
In this task, you will create a small prog ram to produce a short news blurb about a band’s
popular new track and its current performance on two streaming services.
Tip: Remember that links to external sites are generally for interest only, and are not necessary
to complete any task. If required, it will be clearly stated that you must go to an external site.
1. Create a new program (file name music_news.py) with the following code as a starting
point. It is a partial translation of the algorithm shown in step 2 below.
"""
KIT101 3.2PP Latest Music News
"""

__author__ = "YOUR NAME"

def main():
band: str # Band name
track_name: str # Track name
release_day: str # Day of the week the track was released

print("Latest Music News")


print()

band = input("Enter the name of the band: ")


track_name = input("Enter the name of their latest track: ")
release_day = input("Enter the day of the week the track was released: ")

if __name__ == "__main__":
main()

2. Modify the program so that it implements the following algorithm. You will need to declare
additional variables, prompt for and read their values from the user, and produce four
formatted lines of output at the end.
Program: music_news

Variables:
band: str, name of the band
track_name: str, name of the band's latest track
release_day: str, day of the week the track was released
service_a: str, name of the first streaming service
play_count_a: int, number of times the track has been played on the first streaming service
service_b: str, name of the second streaming service
play_count_b: int, number of times the track has been played on the second streaming service
city: str, name of the city the band will be performing in next
total_plays: int, total number of plays across both streaming services

Steps:
1. Display the title of the program: "Latest Music News"
2. Prompt for the band name and store in band
3. Prompt for the track name and store in track_name
4. Prompt for the release day of the track and store in release_day
5. Prompt for the first streaming service name and store in service_a
6. Prompt for the play count on the first streaming service and store in play_count_a
7. Prompt for the second streaming service name and store in service_b
8. Prompt for the play count on the second streaming service and store in play_count_b
9. Prompt for the name of the city the band will play in next and store in city
10. Calculate the sum of play_count_a and play_count_b and store in total_plays
11. Display the following formatted messages across four lines as shown,
where each highlighted word represents that variable's value:
band's latest track, 'track_name', has been well received by fans.
Released on release_day, the track has been played play_count_a times on service_a
and play_count_b times on service_b for a total of total_plays plays to date.
band will play the track live for the first time in city next month.

Example output: When your program is finished it will produce messages that resemble
the following, which is the output from our solution when we gave it the band name
Starfish, the track name Stuck in Mud, a release day of Wednesday, a city name of
London, and play counts of 23456 for Spotify and 28342 for Apple Music.
Starfish's latest track, 'Stuck in Mud', has been well received by fans.
Released on Wednesday, the track has been played 23456 times on Spotify
and 28342 times on Apple Music for a total of 51798 plays to date.
Starfish will play the track live for the first time in London next month.
You should test your program with different inputs to see how it changes.
3. Optional: Change the displayed title of the program to something other than ‘Latest
Music News’.
4. Test your program with a variety of inputs to ensure it works as it should.
5. Take a screenshot of one run of your program and upload both the music_news.py
source file and the screenshot to the assignment submission folder on MyLO.
Suggestion: Can you think of other parts of the message that could be read in from the user to
further customise it? You are not required to make further changes to this task, but if you want
to then you may continue working on a copy as you play with making it more flexible.

"""
KIT101 3.2PP Latest Music News
"""

__author__ = "Test"

def main():
band: str # Band name
track_name: str # Track name
release_day: str # Day of the week the track was released
service_a:str #name of the first streaming service
play_count_a:int # number of times the track has been played on the
first streaming service
service_b:str #name of the second streaming service
play_count_b:int # number of times the track has been played on the
second streaming service
city:str # name of the city the band will be performing in next
total_plays:int # total number of plays across both streaming services
print("Latest Music News")
print()

band = input("Enter the name of the band: ")


track_name = input("Enter the name of their latest track: ")
release_day = input("Enter the day of the week the track was released:
")
service_a = input("Enter the first streaming service name: ")
play_count_a = input("Enter the play count of first streaming service:
")
service_b = input("Enter the second streaming service name: ")
play_count_b = input("Enter the play count of second streaming
service: ")
city = input("Enter the name of the city the band will play in next:
")
total_plays=int(play_count_a) + int(play_count_b)

print(f"{band}'s latest track, '{track_name}', has been well received


by fans.")
print(f"Released on {release_day}, the track has been played
{play_count_a} times on {service_a}")
print(f"and {play_count_b} times on {service_b} for a total of
{total_plays} plays to date.")
print(f"{band} will play the track live for the first time in {city}
next month.")

if __name__ == "__main__":
main()

You might also like