Hello! I am currently learning more in-depth about Python. I have some code that I have made progress on but I am unsure of how to proceed. It is a magic 8-ball
What is the best way to do this? Here is my current code:
import random
# List of magic 8 ball responses responses = [
"Yes, absolutely!",
"Without a doubt, of course, yes.",
"You can count on it!",
"For sure!",
"Hmmm...ask me later",
"I’m not sure",
"I can’t tell you right now",
"I’ll tell you after my nap",
"No way!",
"I don’t think so",
"Absolutely not!",
"The answer is clearly NO!"
]
# Starting function to get a random response from the program
def get_random_response():
return random.choice(responses)
# Main function for the magic 8 ball game
def magic_8_ball():
play_count = 0
Algorithm:
- Define a function get_random_response to get a random response from the list.
- Define a function get_random_response to get a random response from the list.
- Define a function magic_8_ball:
a. Initialize play_count to 0.
b. Start an infinite loop.
c. Prompt the user for a question.
d. If the user types 'quit', exit the loop.
e. Generate a random response using get_random_response.
f. Increment play_count by 1.
g. Print the user's question and the magic 8 ball's response surrounded by asterisks. - After the loop, display the total number of questions asked (play_count).
- Call the magic_8_ball function to run the program.
Step by stepSolved in 4 steps with 3 images
This is perfect, thank you! I have one last question:
Is it possible to also add a 'for' loop while modifying the code so it fits the for loop along with the while loop as well? If so, can you edit and give an example of that please? Thank you!
This is perfect, thank you! I have one last question:
Is it possible to also add a 'for' loop while modifying the code so it fits the for loop along with the while loop as well? If so, can you edit and give an example of that please? Thank you!
- For C programming!! Thank u so much! Write a program that will uses a loop to display a table of the Celsius temperatures 0-20, and the Fahrenheit equivalents. To convert temperatures from Celsius to Fahrenheit, you need to use the following formula: Fahrenheit = Celsuis + 32.arrow_forwardThink of the calculation program completed in week2. What if you wanted to show what the teacher discount amount would be for 5%, 10%, 15%, 20%, and 25%. Write a loop program for the calculated program in week2 to show the teacher discount amount for the different percentages listed above. Below, you will see the sample program from week2. Your program should include: • Variables for each part of problem. See example below: Eg. $apple = 10, $orange = 15, $discount = 0.2 <!DOCTYPE html> <html> <body> <?php $apple = 10; $orange = 15; $discount = 0.2; $subtot = $apple + $orange; echo "Your total before the 20% discount is: "; echo $subtot; $caldiscount = ($apple + $orange) * $discount; $tot = ($apple + $orange) - $caldiscount; echo "<br>Your total after the discount is: "; echo $tot; ?> </body> </html>arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education