This is a console program that rolls a pair of dice and asks the user to guess the sum. If the user's guess is equal to the total value of the dice roll, the user wins. Otherwise, the computer wins.
The program should do the following:
- Roll a pair of dice.
- Add the values of the roll.
- Ask the user to guess a number.
- Compare the user's guess to the total value.
- Determine the winner (user or computer).
To make sure that the rolls are random we imported the randint function from the random module.
To simulate dice rolls: we imported the sleep function from the time module to sleep the program for 2 seconds to simulate the dice rolling.
get_user_guess() : prompt the user for their guess
roll_dice(number_of_sides) : used to simulate the rolling of a pair of dice. A single die can land on any value that’s at least 1 and no greater than the die's number of sides. The randint functions generates a random integer between 1 and number_of_sides. max_val calculates the maximum value the program can possibly roll, which is the number_of_sides times the _number_of_dice.
- Python 2 - Probably will also work for Python 3
NA
Project is: finished
From course Learn Python 2 here: https://www.codecademy.com/learn/learn-python