The program chooses a random integer and based on what number it picks, a certain message will display.  I need help in building an if/else statment where all messages have the same chance of being randomly picked and cannot print more than one message at a time. must use if/else statments i included a screenshot of what the program should accomplish

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

The program chooses a random integer and based on what number it picks, a certain message will display. 

I need help in building an if/else statment where all messages have the same chance of being randomly picked and cannot print more than one message at a time.

must use if/else statments

i included a screenshot of what the program should accomplish 

$ python -m exercises.ex02.fortune_cookie
Your fortune cookie says...
A beautiful, smart, and loving person will be coming
into your life.
Now, go spread positive vibes!
$ python -m exercises.ex02.fortune_cookie
Your fortune cookie says...
Your life will be happy and peaceful.
Now, go spread positive vibes!
$ python -m exercises.ex02. fortune_cookie
Your fortune cookie says...
Soon life will become more interesting.
Now, go spread positive vibes!
Transcribed Image Text:$ python -m exercises.ex02.fortune_cookie Your fortune cookie says... A beautiful, smart, and loving person will be coming into your life. Now, go spread positive vibes! $ python -m exercises.ex02.fortune_cookie Your fortune cookie says... Your life will be happy and peaceful. Now, go spread positive vibes! $ python -m exercises.ex02. fortune_cookie Your fortune cookie says... Soon life will become more interesting. Now, go spread positive vibes!
from random import randint
fortune_one: int = 1
fortune_two: int = 2
fortune_three: int
fortune_four: int = 4
3
fortune_one_message: str = ("Your life will be filled with wisdom and happiness.")
fortune_two_message: str = ("Patience is the key to all life's challenges.")
%3D
fortune_three_message: str =
("The best things in life are yet to come!")
fortune_four_message: str = ("You are going to have a joyful week ahead!")
fortune
randint(1, 4)
%3D
print("Your fortune cookie says...")
if fortune
print(fortune_two_message)
fortune_two:
==
if fortune
fortune_four:
==
print(fortune_four_message)
else:
print(fortune_three_message)
if fortune
print(fortune_one_message)
fortune_one:
else:
print(fortune_threel_message)
print("Now, go spread positive vibes!")
Transcribed Image Text:from random import randint fortune_one: int = 1 fortune_two: int = 2 fortune_three: int fortune_four: int = 4 3 fortune_one_message: str = ("Your life will be filled with wisdom and happiness.") fortune_two_message: str = ("Patience is the key to all life's challenges.") %3D fortune_three_message: str = ("The best things in life are yet to come!") fortune_four_message: str = ("You are going to have a joyful week ahead!") fortune randint(1, 4) %3D print("Your fortune cookie says...") if fortune print(fortune_two_message) fortune_two: == if fortune fortune_four: == print(fortune_four_message) else: print(fortune_three_message) if fortune print(fortune_one_message) fortune_one: else: print(fortune_threel_message) print("Now, go spread positive vibes!")
Expert Solution
Step 1

The program given chooses a random integer and based on the random number choses a respective message is printed in Output. The error in the code given by you is the use of if-else statements. In the required program only simple if-else statements are needed, if we will use nested if-else statements then multiple sentences can be printed and output will be wrong.

Use if-else statements in sequence to check which number is generated, else-if is written as elif in python so I have used this keyword in the code.

Correct Code is Given below.

 

steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
Types of Expressions
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education