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 program with twelve set responses that I have in the first part of the code. I want to add a while loop, a for loop, and an if statement but I am unsure how to proceed. At the end, I also want the user to be able to play again after entering their question and getting a response, while keeping track of how many times they have played and displaying the value once they are done playing. I also want the end output to have the question that the user asked, the response that was randomly selected and asterisks to surround the output so that it looks neat. 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

Microsoft Visual C#
7th Edition
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Joyce, Farrell.
Chapter5: Looping
Section: Chapter Questions
Problem 7RQ
icon
Related questions
Question

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 program with twelve set responses that I have in the first part of the code. I want to add a while loop, a for loop, and an if statement but I am unsure how to proceed. At the end, I also want the user to be able to play again after entering their question and getting a response, while keeping track of how many times they have played and displaying the value once they are done playing. I also want the end output to have the question that the user asked, the response that was randomly selected and asterisks to surround the output so that it looks neat.

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

Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

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

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!

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr