Project Level 1: Beginner
This project is designed for beginner learners who are still learning and practicing Python fundamentals.
Project Description
This project simulates a dice roll by generating a random number between 1 and 6. Each time the program runs, it "rolls the dice" and displays the result. This project introduces students to working with random numbers and basic output formatting.
How the Project Works
The program will use Python’s random module to simulate rolling a six-sided die. Any time the program runs, it displays am message containing the random number:
Prerequisites
Required Libraries: random
Required Files: No files are required.
IDE: You can use any IDE on your computer to code the project.
Danger Zone
Once you code the project, compare it with our two solutions given in the button below.
import random
dice_roll_user = random.randint(1, 6)
dice_roll_computer = random.randint(1, 6)
if dice_roll_user > dice_roll_computer:
print(f'You won the computer! You rolled a {dice_roll_user} and the computer rolled a {dice_roll_computer}.')
elif dice_roll_user == dice_roll_computer:
print(f'You tied with the computer! You rolled a {dice_roll_user} and the computer rolled a {dice_roll_computer}.')
else:
print(f'You lost for computer! You rolled a {dice_roll_user} and the computer rolled a {dice_roll_computer}.')
import random
print("Dice Roll " + str(random.randint(1, 6)))