Complete Python Programming Masterclass Beginner to Advanced
Project #3 – Magic 8 Ball Class
This project will present you with the opportunity to apply the skills that you have learned up to this point with the course.
3.1 READING CONTENT FROM A .CSV FILE
In the first part of this project you will create the basics of the magic8ball class
Step 1
Build the basic class structure
Import the necessary modules
ie. random, sys, csv
Name the class “magic8ball”
Step 2
Create the class __init__ method
Pass in the “self” and a “name” argument
Include an additional private property called “__mQuestions” and make it equal to an empty list.
This will be used later to append the questions asked by the user.
3.2 Adding Game Functionality
In the second part of the project you will build the game loop. The user should be able to ask questions and receive random responses from the magic 8 ball.
Step 1
Create a new private method called “__start_game”
Include the “self” argument
This method will perform the bulk of the work.
Create a loop to continuously prompt the user to ask questions
If a question is asked, then a random magic 8 ball response should be printed to the screen. If no question is asked, then the game should exit.
Each question asked should be appended to the “__mQuestions” list from the __init__ method
3.3 Writing Questions to the magic_questions.csv file
In the third part of this project you will create a method to write all the questions asked to a .csv file.
Step 1
Create a private method called “__write_questions”
Include the “self” argument
Using the csv module this method should write all the questions to the provided “magic_questions.csv” document when the user exits the game.