Statistics After the simulation, you will prepare and return these stats on your village's parties: 1. unheard_songa: The set of songs that have never been heard by non-hards. 2 billboard_tog: A list of the n best-known songs in descending order from snags known by the most people to sangs known by the fewest. Break ties alphabetically, according to Python's sort order of strings. (IIINT: the list aort method is going to be very helpful here. What criterina does it sort on by default? Ilow many times will you need to sart? What can the key parameter be used for?) 3-a11 barda: The set of people who are hards, whether they started out as one or became one by learning enough songs. 4-average attendees: The average number of people at a party. Round up to the nearest integer (so both 1.7 and 1.1 should become 2).

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
Background
Once upon a time, in a certain medieval village, a group of mysterious strangers
appeared in jeans and T-shirts. The strangers managed to learn enough Old
English to explain that they had been enjoying their favourite pastime-belting
out tunes ata karaoke party-when they saw a blinding flash and heard a
thundemus roar, Inst consciousness, and found themselves transported hack in
time without any explanation.
The villagers were most interested in the strangers' wide-ranging komledge af
popular snags from the future. They understood that the strangers belnaged to
some sort of hard class. The villagers were also party animals, and had a feast
every night. The bands agreed to come to some of the parties and sing ane
Dillboard Top 40 song whenever they did. When they weren't there, the villagers
would sing these songs to each other, reverently, knowing that they held clues to
the future of their world. The more they learned, the more they were able to
share, and some were even initiated into the mysterious strangers' inner cirde
and allowed to become hards themselves.
Your task
Simulate the above village with its nightly parties.
You'll be given a list of villagers and hards. You'll also get a list of snags. The
bards start out knowing every song, hut no one eke koms anysnags
You'll be given a list of parties with their attendees, in the order that the parties
are held. Every party features singing. There are two ways a party can unfold:
If there's at least one hard present, they sing a song that none of the regular
villagers at the party konw yet. Specifically, the hard sings the first new song
alphabetically, according to Python's snot arder af strings
. If there are no hards present, everyme at the party sings all the songs they
know at that point.
Either way, whenever a snog is sung, everyone at the party learns and remembers
it.
If a villager leams enough songs, and they're at a party with a bard, they too
become a bard and learn every snag
Finally, you'Il calculate some statistics about the simulation.
Sets
One of the concepts you'll be practicing throughout this assignment is sets.
Aset is very much like a list, with a few differences
• There are no duplicate values in a set. No matter what you do, values are
always unique.
Sets have no order. There are no indices and you can't access individual
elements.
• Checking whether a value is in a set is instantanenos, no matter the size.
.
Sets have their own set of operations as described in set theory. You may find
set union and set difference useful and, in general, you will find sets a valuable
tool throughout this assignment.
Input File
Each test case is one input file. Here's a sample input file
VILLAGERS
Luke Sarczak
Dan Zingaro
Freddie Prinze 3r.
Arnold Rosenblecn
SONGS
Pacple, I've Been Sad
Call Me Mayba
What a Man Gotta De
Dalata Forever
PARTIES
Dan Zingaro, Freddie Prinze 3r.,Arnold Rosenblcom
Arnold Rosenbleon, Luke Sarczak, Freddie Prinze 3r.
Dan Zingare, Luke Sarczak
Freddie Prinze 3r.,Luke Sauczak, Arnold Rosenblcom
People with an asterisk after their name are hards. However, the asterisk isa't
part of their name-notice there are no asterisks in the list of parties.
Of course, there may be any number of villagers, hards, songs, and parties
(including zern). An important task is to write the readingut function, which
parses the input into the villagers, bards, songs, and parties structures in Pythoa.
(HINT: how can you tell when ane part of the file end? You need to keep track of
which part of the file you are working on now!)
Walkthrough of the above example
Let's say for this example that the threshold to become a hard is a songs. The first
party has a bard, Dan. He's a bard so he koms every soog. Hesings Call Me
Mayhe (the first alphabetical snog that no ane at the party knows). At the next
party, there's no hard, but Amold and Freddie teach Call Me Maybe to Luke. At
the third party, Dan the bard is hack. Since Luke already knows Call Me Maybe,
Dan dehuts Delete Forever next. At the fourth party, Luke teaches Freddie and
Aroald Delete Forever. Under our assumption that the threshold to become a
bard is 2 songs, Lake would have qualified to be a hard after the third party, and
Freddie and Amald after the fourth party.
Transcribed Image Text:Background Once upon a time, in a certain medieval village, a group of mysterious strangers appeared in jeans and T-shirts. The strangers managed to learn enough Old English to explain that they had been enjoying their favourite pastime-belting out tunes ata karaoke party-when they saw a blinding flash and heard a thundemus roar, Inst consciousness, and found themselves transported hack in time without any explanation. The villagers were most interested in the strangers' wide-ranging komledge af popular snags from the future. They understood that the strangers belnaged to some sort of hard class. The villagers were also party animals, and had a feast every night. The bands agreed to come to some of the parties and sing ane Dillboard Top 40 song whenever they did. When they weren't there, the villagers would sing these songs to each other, reverently, knowing that they held clues to the future of their world. The more they learned, the more they were able to share, and some were even initiated into the mysterious strangers' inner cirde and allowed to become hards themselves. Your task Simulate the above village with its nightly parties. You'll be given a list of villagers and hards. You'll also get a list of snags. The bards start out knowing every song, hut no one eke koms anysnags You'll be given a list of parties with their attendees, in the order that the parties are held. Every party features singing. There are two ways a party can unfold: If there's at least one hard present, they sing a song that none of the regular villagers at the party konw yet. Specifically, the hard sings the first new song alphabetically, according to Python's snot arder af strings . If there are no hards present, everyme at the party sings all the songs they know at that point. Either way, whenever a snog is sung, everyone at the party learns and remembers it. If a villager leams enough songs, and they're at a party with a bard, they too become a bard and learn every snag Finally, you'Il calculate some statistics about the simulation. Sets One of the concepts you'll be practicing throughout this assignment is sets. Aset is very much like a list, with a few differences • There are no duplicate values in a set. No matter what you do, values are always unique. Sets have no order. There are no indices and you can't access individual elements. • Checking whether a value is in a set is instantanenos, no matter the size. . Sets have their own set of operations as described in set theory. You may find set union and set difference useful and, in general, you will find sets a valuable tool throughout this assignment. Input File Each test case is one input file. Here's a sample input file VILLAGERS Luke Sarczak Dan Zingaro Freddie Prinze 3r. Arnold Rosenblecn SONGS Pacple, I've Been Sad Call Me Mayba What a Man Gotta De Dalata Forever PARTIES Dan Zingaro, Freddie Prinze 3r.,Arnold Rosenblcom Arnold Rosenbleon, Luke Sarczak, Freddie Prinze 3r. Dan Zingare, Luke Sarczak Freddie Prinze 3r.,Luke Sauczak, Arnold Rosenblcom People with an asterisk after their name are hards. However, the asterisk isa't part of their name-notice there are no asterisks in the list of parties. Of course, there may be any number of villagers, hards, songs, and parties (including zern). An important task is to write the readingut function, which parses the input into the villagers, bards, songs, and parties structures in Pythoa. (HINT: how can you tell when ane part of the file end? You need to keep track of which part of the file you are working on now!) Walkthrough of the above example Let's say for this example that the threshold to become a hard is a songs. The first party has a bard, Dan. He's a bard so he koms every soog. Hesings Call Me Mayhe (the first alphabetical snog that no ane at the party knows). At the next party, there's no hard, but Amold and Freddie teach Call Me Maybe to Luke. At the third party, Dan the bard is hack. Since Luke already knows Call Me Maybe, Dan dehuts Delete Forever next. At the fourth party, Luke teaches Freddie and Aroald Delete Forever. Under our assumption that the threshold to become a bard is 2 songs, Lake would have qualified to be a hard after the third party, and Freddie and Amald after the fourth party.
Statistics
After the simulation, you will prepare and return these stats on your village's
parties:
1. unheard songs: The set of songs that have never been heard by non-hards
2 billboard-top: A list of the n best-known songs in descending order from
snags known by the most people to songs known by the fewest. Break ties
alphabetically, according to Python's sort order of strings. (IIINT: the list
sort method is going to be very helpful here. What criterion does it sort on by
default? Ilow many times will you need to sart? What can the key parameter
be used for?)
3-a11 barda: The set of people who are hards, whether they started out as one
or became one by learning enough songs.
4-average attendees: The average number of people at a party. Round up to
the nearest integer (so both 17 and 1.1 should become 2).
Starter code
Please find your starter ende and test examples in Markus.
In bard.py, you'll find functions marked with roco whose implementations you
must complete.
You also have a couple of inport statements to make the type annotations work
and constants for the number of songs a villager must know to become a hard and
the number of Billboard Top songs.
Take some time to read over the starter ende to understand the structure, as well
as the functions you've been given and the functions you must write.
Testing
We have a thorough set of tests on which we'll run your code. Everything we'll
test has been discussed here and in the starter code, so please read both carefully!
The starter code has some tests, including one balistic test (the statistics you
should output for the sample given above), which you can try out by running
test bard.gy.
F.A.Q.
Can there be duplicate villager names or song names?
No.
What happens if there are multiple hards at a party?
Only one of them sings. It doesn't matter which ane, since they would all choose
the same next snog.
What happens if there are only hards at a party?
Whether anyone sings or not makes no difference since all the hards already
know all the songs.
What happens if there are no new songs for a hard to sing?
The party is boring. No one sings. Nothing changes.
What happens if a party has no bard, but during the party a villager
learns enough songs to become one?
A villager can only become a hard at a party that already has a bard, so this can't
happen. A party either has a hard at the beginning or doesn't, and a party's status
never changes once it's begun.
If there's a party where a villager learns enough songs to become a
bard but there isn't a hard at the party, do they miss their chance?
No, they become a hard at the next party they attend where there's a hard (if they
ever attend such a party).
Important Reminders
. Compared to prior assignments, note this time that we are asking you to write
functions that do what we have specified. None of your functions should use
ingut ar print.
. Please don't change what you have been given in the starter code. If you do,
then our correctness tests on your ende will not work correctly.
. For the code we have given you, do not add ar remove any parameters,
change any parameters or return types, or change any type annotations.
Please don't add additional import statements.
. You can and should add helper functinas to keep your code organized.
Test, test, test! The test cases that we give you are not to be easidered full
testing.
Please submit all of your files to Markus.
You must work akme on this assignment.
The final thing you should do is to open your code files in Notepad and make
sure that the code displays correctly as only Python ende.
Transcribed Image Text:Statistics After the simulation, you will prepare and return these stats on your village's parties: 1. unheard songs: The set of songs that have never been heard by non-hards 2 billboard-top: A list of the n best-known songs in descending order from snags known by the most people to songs known by the fewest. Break ties alphabetically, according to Python's sort order of strings. (IIINT: the list sort method is going to be very helpful here. What criterion does it sort on by default? Ilow many times will you need to sart? What can the key parameter be used for?) 3-a11 barda: The set of people who are hards, whether they started out as one or became one by learning enough songs. 4-average attendees: The average number of people at a party. Round up to the nearest integer (so both 17 and 1.1 should become 2). Starter code Please find your starter ende and test examples in Markus. In bard.py, you'll find functions marked with roco whose implementations you must complete. You also have a couple of inport statements to make the type annotations work and constants for the number of songs a villager must know to become a hard and the number of Billboard Top songs. Take some time to read over the starter ende to understand the structure, as well as the functions you've been given and the functions you must write. Testing We have a thorough set of tests on which we'll run your code. Everything we'll test has been discussed here and in the starter code, so please read both carefully! The starter code has some tests, including one balistic test (the statistics you should output for the sample given above), which you can try out by running test bard.gy. F.A.Q. Can there be duplicate villager names or song names? No. What happens if there are multiple hards at a party? Only one of them sings. It doesn't matter which ane, since they would all choose the same next snog. What happens if there are only hards at a party? Whether anyone sings or not makes no difference since all the hards already know all the songs. What happens if there are no new songs for a hard to sing? The party is boring. No one sings. Nothing changes. What happens if a party has no bard, but during the party a villager learns enough songs to become one? A villager can only become a hard at a party that already has a bard, so this can't happen. A party either has a hard at the beginning or doesn't, and a party's status never changes once it's begun. If there's a party where a villager learns enough songs to become a bard but there isn't a hard at the party, do they miss their chance? No, they become a hard at the next party they attend where there's a hard (if they ever attend such a party). Important Reminders . Compared to prior assignments, note this time that we are asking you to write functions that do what we have specified. None of your functions should use ingut ar print. . Please don't change what you have been given in the starter code. If you do, then our correctness tests on your ende will not work correctly. . For the code we have given you, do not add ar remove any parameters, change any parameters or return types, or change any type annotations. Please don't add additional import statements. . You can and should add helper functinas to keep your code organized. Test, test, test! The test cases that we give you are not to be easidered full testing. Please submit all of your files to Markus. You must work akme on this assignment. The final thing you should do is to open your code files in Notepad and make sure that the code displays correctly as only Python ende.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

A BARD DAY'S NIGHT
a.k.a. BARD ROCK CAFE
a.k.a. THE SCHOOL OF BARD KNOCKS
a.k.a. A BARD RAIN'S A-GONNA FALL
"""

# Imports

from typing import Optional, TextIO # Specific annotations

from math import ceil # For stats

# Constants

# Minimum number of songs for a villager to be promoted to a bard
BARD_THRESHOLD = 10

# Number of songs for the billboard_top statistic
BILLBOARD_N = 10


# DO NOT use these as variables in your code;
# they are only for type contracts.

# Maps from {name: songs that this villager knows}
villagers_type = dict[str, set[str]]

bards_type = set[str]

# Maps from {song name: names of people, including bards, that know this song}
songs_type = dict[str, set[str]]

# A list of parties; each party is a set of the attendee names
parties_type = list[set[str]]


def read_input(
f: TextIO,
) -> tuple[villagers_type, bards_type, songs_type, parties_type]:
"""
Read the given file and return the villagers, bards, songs, and parties.

f is an open file containing VILLAGERS and bards, SONGS, and PARTIES,
in that order. One villager or bard per line;
one song per line; one party per line, consisting of attendees
separated by commas. The parties are given in the order they're held.

"""
# TODO
pass


# Party functions
# We highly recommend adding helper functions here!

def sing_at_party(
villagers: villagers_type, bards: bards_type, songs: songs_type, party: set[str]
) -> None:
"""
A bard sings if present, otherwise the villagers sing.
"""
# TODO
pass

def update_bards_after_party(
villagers: villagers_type, bards: bards_type, songs: songs_type, party: set[str]
) -> None:
"""
Promote attendees who have learned enough songs to bards,
iff there is another bard present at the party.
"""
# TODO
pass


# Stats functions

def unheard_songs(
villagers: villagers_type,
bards: bards_type,
songs: songs_type,
parties: parties_type,
) -> set[str]:
"""
Return a set of songs that have never been heard by non-bards.
(This means that only the bards know it.)
"""
# TODO
pass

def billboard_top(
villagers: villagers_type,
bards: bards_type,
songs: songs_type,
parties: parties_type,
) -> list[str]:
"""
Return a list of the BILLBOARD_N most popular songs by number of people
who know them, in descending order. Break ties alphabetically.
"""
# TODO
pass

def all_bards(
villagers: villagers_type,
bards: bards_type,
songs: songs_type,
parties: parties_type,
) -> set[str]:
"""Return the set of the village's bards."""
# TODO
pass

def average_attendees(
villagers: villagers_type,
bards: bards_type,
songs: songs_type,
parties: parties_type,
) -> int:
"""
Return the average number of attendees at parties in the village.
Round up to the nearest integer.
"""
# TODO
pass


# Main process

def run(filename: str) -> dict[str, object]:
"""
Run the program: read the input, host the parties,
and return a dictionary of resulting statistics keyed by name:
unheard_songs, billboard_top, all_bards, average_attendees

filename is the name of an input file.
"""
# TODO
pass


# Run program

if __name__ == "__main__":

# Sample input from the handout -- you can tweak this if you like
stats_handout = run("handout_example.txt")
print("Results of handout sample input")
for key, value in stats_handout.items():
print(f"{key}: {value}")

print()

# Sample bigger input -- you can tweak this if you like
stats_bigger = run("bigger_example.txt")
print("Results of bigger sample input")
for key, value in stats_bigger.items():
print(f"{key}: {value}")

Solution
Bartleby Expert
SEE SOLUTION
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY