Answered step by step
Verified Expert Solution
Question
1 Approved Answer
CPT 180 Chapter 3 Assignment 1 Directions Using the following guidelines, create a python program. 1. Create the program magic8Ball.py from page 64 (60 in
CPT 180 Chapter 3 Assignment 1 Directions Using the following guidelines, create a python program. 1. Create the program magic8Ball.py from page 64 (60 in 2nd Edition). 2. Add three comment lines at the top of the program that contain: a. Program Name b. Program Description C. Programmer's Name (You) 3. Add code before the function that will prompt the user for the following: a. User's name b. A Yes or No question 4. Create code to produce an output formatted as shown in the Example Output. 5. Submit the magicBall.py file into the Chapter 3 Assignment 1 Submission Folder. Return values and return Statements When you call the len() function and pass it an argument such as 'Hello', the function call evaluates to the integer value 5, which is the length of the string you passed it. In general, the value that a function call evaluates to is called the return value of the function. When creating a function using the def statement, you can specify what the return value should be with a return statement. A return statement con- sists of the following: The return keyword The value or expression that the function should return When an expression is used with a return statement, the return value is what this expression evaluates to. For example, the following program defines a function that returns a different string depending on what num- ber it is passed as an argument. Enter this code into the file editor and save it as magicBall.py: import random def getAnswer (answerNumber): if answer Number -- 1: return 'It is certain elif answer Number - 2: return 'It is decidedly so elif answer Number -- 3: return 'Yes' elif answer Number == 4: return 'Reply hazy try again elif answer Number - 5: return 'Ask again later elif answerNumber == 6: return 'Concentrate and ask again! elif answer Number -- 7: return 'My reply is no elif answerNumber == 8: return Outlook not so good' elif answer Number -- 9: return 'Very doubtful Or - random.randint(1, 9) fortune - getAnswer(r) print(fortune)
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