 # Python 2 Number Guess Game

#1

I made a couple additions to the Python 2 Number Guess project while trying to follow its original style. Might do more, such as continuation of play. Any suggestions?

``````"""
Number Guess
The program should do the following:

Roll user input number of dice.
Add the values of the roll.
Ask the user to guess a number.
Compare the user's guess to the total value.
Human wins if guess matches computer roll total.
"""
from random import randint
from time import sleep

def get_user_guess():
guess = int(raw_input("Enter guess: "))
return guess

def get_number_of_dice():
number_of_dice = int(raw_input("How many dice would you like to play with(1 to 9): "))
return number_of_dice

def get_number_of_sides():
number_of_sides = int(raw_input("How many sides would you like each die to have(3 to 20): "))
return number_of_sides

def roll_dice(number_of_dice, number_of_sides):
dice = []
for roll in range(number_of_dice):
dice.append(randint(1, number_of_sides))
max_val = number_of_dice * number_of_sides
print("The lowest possible roll is: %d" % number_of_dice)
print("The highest possible roll is: %d" % max_val)

guess = get_user_guess()
if guess > max_val or guess < number_of_dice:
print("Invalid Guess. Goodbye.")
else:
print("Rolling...")
sleep(2)
for roll in range(number_of_dice):
print("Die {}: {}".format(roll+1, dice[roll]))
sleep(1)
total_roll = sum(dice)
print("Total Roll: %d" % total_roll)
print("Result...")
sleep(1)
if guess == total_roll:
print("You win!!!")
else:
print("Sorry, you have lost.")

def play_dice_game():
print("Playing Dice Game")
number_of_dice = get_number_of_dice()
if number_of_dice < 1 or number_of_dice > 9:
print("Invalid number of dice. Goodbye.")
else:
number_of_sides = get_number_of_sides()
if number_of_sides < 3 or number_of_sides > 20:
print("Invalid number of sides. Goodbye.")
else:
roll_dice(number_of_dice, number_of_sides)

play_dice_game()
``````