rolled = random.randint(1,6) If we want to show our selected number, we can use print (). Your code should look like this: import random rolled - random.randint(1,6) print(rolled) Nice, we already have our main engine working, now it's time to make it look more appealing. To do that we will add some improvements (we will use a new variable to store random generated numbers – rolled_num) import random rolled_num = random.randint (1,6) print("You rolled: ", rolled_num)

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
Make A Dice Simulator in Python. First, we import the library that allows us to choose random
numbers.
import random
Now, we can generate a random number and save it in a variable, We will call it rolled
Python library random has a function called randint (). The randint (min number, max
number) requires 2 parameters (the lowest number and the highest number between we
will pick our number randomly). In this case, our dice goes between 1-6.
rolled = random.randint (1,6)
If we want to show our selected number, we can use print (). Your code should look
like this:
import random
rolled - random.randint(1,6)
print(rolled)
Nice, we already have our main engine working, now it's time to make it look more
appealing. To do that we will add some improvements (we will use a new variable to
store random generated numbers - rolled_num)
import random
rolled num - random.randint(1,6)
print("You rolled: ", rolled num)
If we run the code again, we should see a little message and the random number. Our
code runs only once and then it close. What we need is to keep it running. To
accomplish this, we will used while.
import random
while True:
rolled_num = random.randint(1,6)
print("The dice rolled and you got: ", rolled_num)
input("Press any key to roll again.")
If you run this code, you will see that the dice will keep rolling as long as you press any
key.
Improve this code even more!
(Hint: one possibility, use break if the same number is generated twice)
Transcribed Image Text:Make A Dice Simulator in Python. First, we import the library that allows us to choose random numbers. import random Now, we can generate a random number and save it in a variable, We will call it rolled Python library random has a function called randint (). The randint (min number, max number) requires 2 parameters (the lowest number and the highest number between we will pick our number randomly). In this case, our dice goes between 1-6. rolled = random.randint (1,6) If we want to show our selected number, we can use print (). Your code should look like this: import random rolled - random.randint(1,6) print(rolled) Nice, we already have our main engine working, now it's time to make it look more appealing. To do that we will add some improvements (we will use a new variable to store random generated numbers - rolled_num) import random rolled num - random.randint(1,6) print("You rolled: ", rolled num) If we run the code again, we should see a little message and the random number. Our code runs only once and then it close. What we need is to keep it running. To accomplish this, we will used while. import random while True: rolled_num = random.randint(1,6) print("The dice rolled and you got: ", rolled_num) input("Press any key to roll again.") If you run this code, you will see that the dice will keep rolling as long as you press any key. Improve this code even more! (Hint: one possibility, use break if the same number is generated twice)
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY