Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Help! I'm struggling with this computer science assignment and could use some guidance! from eightball.py: Background We have already worked with if statements to detect
Help! I'm struggling with this computer science assignment and could use some guidance!
from eightball.py:
Background We have already worked with if statements to detect invalid input. But in some cases users will repeatedly enter the wrong value. In addition, some problems lend themselves to executing the program repeatedly. This lab will explore these uses of loops in Python. Objectives - Use a loop structure for error correction. - Use a loop structure for execution control. Part 1: The Magic 8-Ball The Magic 8-Ball is a toy produced by Tyco Toys (now Mattel) and consists of a ball filled with a blue fluid. Suspended in the fluid is a icosahedron (a 20sided polyhedron with each side consisting of an equilateral triangle). Each face has an answer to a yeso question. Download the eightball.py program then implement the required helper functions: This function is simpler than the previous input functions you have written. Display the prompt (followed by " [yes / no ]: "), read the next line of user input, and return true if it's " y " or "yes" ignoring case. Hint: You can use string.lower() to ensure lowercase for all inputs. This function should keep prompting the user to enter a question until they enter a valid one. Question strings must be between 1 and 60 characters, and they must end with a question mark to be valid. If the question is invalid, display the applicable error message: - "Your question is blank" - length less than 1 - "Your question is too long" - length longer than 60 - "Is this valid?" - doesn't end with '?' Test the program multiple times with different inputs. - Your final version should allow you to keep asking questions as long as you enter the word "yes" or " y ". - The main function should also verify the validity of the question before printing the answer. Here is an example of what it will look like: answer_str = answers[answer_index] \# output the results print(f"Question: \{question\} \ " ) print(f" Answer: \{answer_str\} ) print("Goodbye!")Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started