تم الحل ✓
categoryهندسة الحاسبات
schoolبكالوريوس
event_available2026-07-15
السؤال
Transcribed Image Text:
Programming Assignment
1 MAGIC EIGHT BALL (100 POINTS)
Have you ever wanted to predict the future? Well the Magic Eight Ball does just that. The original
game was a softball sized "8-ball". You would ask a question, shake it up and look at the result
There are 20 responses.10 positive, 5 negatives, and 5 are vague For this project, we want to
recreate this, but give the ability to read in a set of responses, and add additional responses, and
print out all of the responses in alphabetical order. Of course, we have to give seemingly accurate
responses, which we will do by giving a random response
Program Details:
You should have a menu with five lettered options. You should accept both capital and lower-
case letters in your menu options. The menu should do the task, then retum to the menu (except
in the case of exit). Any incorrect responses should get an error message followed by a reprint
of the menu.
a. Read Magic 8 Ball responses from a file
b. Play Magic Eight Ball
c. Print out responses (and their categories)
d. Print out responses grouped by category
e. Write responses to a file
Exit
Each menu item must be implemented using one or multiple classes within a single python
module with appropriate attributes, input parameters and return values (except for exit). For
example, for menu option a. a module called responses.py implements one or more function that
handle the use cases (requirements) described by the menu (see implementation details below).
Also, you will have parallel lists or a dictionary for responses and categories that keeps track of
the response and whether it is positive, negative, or vague. The parallel list or dictionary will
then be passed as parameters to the other functions
Implementation Detail 1: Create a python classes and modules as follows
menu.py (10 points)
MenuOption class with the following attributes
L Public variable instances representing each menu.
ii. Example:
Class Pemudpresion
Read Hagic
Ball responses from a file
The Play Magic Eight Ball
Page 1 of 4
Programming Assignment
Menu class with at least the following attributes
CSC11410-002
LA private instance variable called mena of type str that stores a formatted
menu as shown above.
il. A private instance variable called selected mene of type MenuOption that
stores the active, selected menu
iii. A constructor that takes no parameters but initializes mu
iv. A private function named display mens that display the menu on console
v. An accessor function to selected men
vi. A public method called select) that prompts user to select a me uption
from the available options and returna the selected option. Must
implement input validation using an indefinite loop.
b. responses.py (20 points)
Responses class with the following attributes
Constructor that takes in a file name ( definit self, filename))
il A private instance called responses of type diet that stones responses as
keys and their categories as value.
1. Dict Example: ('It is certain': 'positive'
Alternatively, responses can be of type tuple of parallel lists that stores
the responses in one list and the corresponding categories in another list
Make sure the indices of the responses and categories are matched
2. Tuple of lists Example (It is certain'), l'positive'))
ii. A read function that meads and populates responses
iv. A sort() function that sorts the responses array in descending alphabetical
order. Note: Must implement one of the sorting algorithms discussed in
dase Selection sort, bubble sort
v. A write function responsible for dumping the content of the dict to file
This function must prompt the user for output file name
vi Accessor method to retrieve responses
vi
A printo function that prints the response and categories to console, Make
sire this function contains an option to print the responses in alphabetical
order (required by option C of the menu))
vi Mutator function called updated to update responses. This function must
prompt the user to enter the response and its category, validate the input,
then update the responses container with the newly added response
magic.py (20 peints
Magic clam with the following attributes
Programming Assignment
CSC1410-002
A constructor that takes in a Responses object
Call the read function of responses object in the constructor to
populate the sponses container
1. A private instance called responses for storing the Responses object
passed in the constructor
i. A function called shake) that retums a random response and its category
from the list of responses
d. game.py (20 points)
•
Gameloop class that implements the game loop. Includes at least the following
attributes
LA constrictor that takes no parameters but initializes the following
variable instances
• Home Falar
.
sponses object
magics object
menu object
A method ralled run that starts the game loop and handles every menu-
aption
main.py (30 points
Must implement an interactive loop continuously prompting user
to elect from menu
Use if elif else conditional to handle menu selection a
End the loop when user selects option for exit.
Implements the entry point to the game
Must include a main block
Immediately prints a brief description of the project then starts the game loop
Implementation Detail 2
Furated output and proper user interaction (10 points)
Frans as expected 130 points)
mming Assignment
The format of the content in input.txt file is as follows:
It is certain: positive
It is decidedly so: positive
Without a doubt: positive
Yes definitely: positive
You may rely on it: positive
As I see it, yes: positive
Most likely: positive
Outlook good positive
Yes: positive
Signs point to yes; positive
Reply hazy try again: vague
Ask again later: vague
Better not tell you now: vague
Cannot predict now: vague
Concentrate and ask again: vague
Don't count on it: negative
My reply is no negative
My sources say no negative
Outlook not so good: negative
Very doubtful: negative
check_circle الجواب — حل مفصل خطوة بخطوة
hourglass_top
🔒
الحل الكامل متاح للمشتركين
اشترك في أرشيف الأسئلة لعرض هذا الحل وآلاف الحلول المفصلة خطوة بخطوة من معلمين معتمدين.