Question

Python 3.8.1 (tags/v3.8.1:16293b6, Dec 18 2019, 22:39:24) [MSC v.1916 32 bit (In tel)] on win32 Type help, copyright, crYour friend is writing a Python program to randomly provide the user with an inspiring quote. Unfortunately, your friend is a terrible programmer, and you promised to help them with their program.

Basically, there is a list of inspirational sayings in the code, and the program enters a loop and gives the user a random quote. The program is then supposed to ask the user if they want another quote. If they answer anything other than ‘y’ the program ends.


There’s one more requirement, the program needs to automatically adjust the maximum random numbers value returned to match the total number of quotes.

Below is the code that was written. You are to copy the code shown below (between the start and end lines) into your Python editor or IDE, fix the code so that it works, and copy the correct code into the essay box below. Make sure to test the code fully to ensure it is truly working.

***** Start of Code *****
# sayings must be a list of sayings
sayings =
'Today will be a wonderful day!',
'You are going to realize your dreams!',
'Soon your ideas will be appreciated by others!',
'Doors are opening because of your hard work!',
'Your dreams are about to come true.'

count_sayings = 10

get_saying = true

# enter into a loop while the user wants to continue to play
while get_saying = true:
saying_index = randint(0, count_sayings) # get a random index value
print('\n')
print('----- Your Saying for Today -----')
print(sayings) # print the random saying

print('\n')
user_response = 'Would you like another inspirational saying? (y/n) '
if response = 'y':
saying = False;

#print final message as the game play ends.
print('Thank you for playing, please come again.')
***** End of Code *****

Running correctly, the output from your application should appear as follows:

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import random #to randomly choose a value
sayings =['Today will be a wonderful day!',
          'You are going to realize your dreams!',
          'Soon your ideas will be appreciated by others!',
          'Doors are opening because of your hard work!',
          'Your dreams are about to come true.'] #all the sayings in the list
while True: #infinite loop breaks when user inputs anything other than 'y'
    count = len(sayings) #gets the number of elements in the list, THIS SHOULD SOLVE YOUR PROBLEM
    saying_index = random.randint(0, count-1)
    #get a random index value, (count -1) since randint takes both numbers inclusive
    print('\n')
    print('----- Your Saying for Today -----')
    print(sayings[saying_index]) # print the random saying using the index value
    print('\n')
    response = input('Would you like another inspirational saying? (y/n)')
    #takes the user input if continue for more quotes
    if response != 'y': #checking the input
        break #break the loop
print('Thank you for playing, please come again.')

1 2 5 7 8 9 main.py x main2.py X import random #to randomly choose a value sayings =[Today will be a wonderful day!, 3 YouFile Edit View Navigate Code Refactor Run Tools VCS Window Help python Project - main2.py python Project to main2.py main.py

Add a comment
Know the answer?
Add Answer to:
Your friend is writing a Python program to randomly provide the user with an inspiring quote....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a Python program (using python 3.7.2) that lets the user play the game of Rock,...

    Write a Python program (using python 3.7.2) that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows. 1. When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. (Don’t display the...

  • Using python, write code for problem. Please also put screenshot of your code. The following program...

    Using python, write code for problem. Please also put screenshot of your code. The following program will perform properly if the user enters 0 in response to the request for input. However, the program will crash if the user responds with "eight". Rewrite the program using a try/except statement so that it will handle both types of responses. See Fig. 6.1. while True: n = int (input ("Enter a nonzero integer: ")) if n! = 0: reciprocal = 1/n print...

  • Modular program mathlab: Write a program in Matlab that would continuously ask the user for an...

    Modular program mathlab: Write a program in Matlab that would continuously ask the user for an input between 1 and 6, which would represent the result of rolling a die. The program would then generate a random integer between 1 and 6 and compare its value to the value entered by user. If the user’s die is larger, it should display, “You got it” If the user’s die is smaller, it should display, “Nice try” If the results are the...

  • write in python Create a program that will ask the user for a list of integers,...

    write in python Create a program that will ask the user for a list of integers, all on one line separated by a slash. construct a list named "adj_numbers" which contains the users input numbers after subtracting 2 from each number. then print the resulting list. the input statement and print statement are given to you in the starting code. a sample run of the program is as follows: Enter a list of integers, separated by slashes: 7/3/6/8 resulting list:...

  • Write python program using IDLE Write a full program that asks the user to enter his/her...

    Write python program using IDLE Write a full program that asks the user to enter his/her name then repeatedly ask to enter the temperature in Fahrenheit and convert it to Celsius, the program should then prompt the user if he/she wants to continue or exit the program. The formula for the conversion is: °C = (°F - 32) x 5/9 The program should use a function for the conversion. An Example of a sample run should appear on the screen...

  • Vending Machine (Python 3) Thinking Outside the box Write a program that asks the user to...

    Vending Machine (Python 3) Thinking Outside the box Write a program that asks the user to enter a bill value (1 = $1 bill, 5 = $5 bill, etc.) and the price of an item they want to buy in pennies and calculate their change amount in dollars, quarters, dimes, nickels, and pennies. Your code should start like this: ## # This program simulates a vending machine that gives change # Define constants PENNIES PER DOLLAR = 100 PENNIES PER...

  • For this lab, modify the python code below so it will continuously be asking user for...

    For this lab, modify the python code below so it will continuously be asking user for inputs to calculate the interest earned until the user enters number 0 (zero) in principle. Once the user enters any number less or equal to 0 in principle, the program will end. here is my code: # Programming Exercise 3-14 # Local variables p = 0.0 r = 0.0 n = 0.0 t = 0.0 loop = True while loop: p = float(input('\nEnter the...

  • write in python idle Write full program that asks the user to enter his/her name then...

    write in python idle Write full program that asks the user to enter his/her name then repeatedly ask to enter the temperature in Fahrenheit and convert it to Celsius, the program should then prompt the user if he/she wants to continue or exit the program. The formula for conversion is: °C = (°F - 32) x 5/9 The program should use a function for the conversion. An Example of a sample run should appear on the screen like the text...

  • mathTutor Write a program that selects two random numbers -20 to 20. The two numbers would...

    mathTutor Write a program that selects two random numbers -20 to 20. The two numbers would get displayed with "+" between them. The user should enter the sum of the two numbers. The program should print "Incorrect" if the user enters a wrong answer and re-prompts the user to re-enter the answer again. Limit the number of incorrect tries to 3. After 3 incorrect tries print the correct answer. The program should print a message like "Correct!" if the user...

  • mathTutor Write a program that selects two random numbers -20 to 20. The two numbers would...

    mathTutor Write a program that selects two random numbers -20 to 20. The two numbers would get displayed with "+" between them. The user should enter the sum of the two numbers. The program should print "Incorrect" if the user enters a wrong answer and re-prompts the user to re-enter the answer again. Limit the number of incorrect tries to 3. After 3 incorrect tries print the correct answer. The program should print a message like "Correct!" if the user...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT