Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.04 KB | None | 0 0
  1. """In this project, we'll build a 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."""
  2.  
  3. from random import randint
  4. from time import sleep
  5.  
  6. def get_user_guess():
  7.   guess = int(raw_input("Guess a number!"))
  8.   return guess
  9.  
  10. def roll_dice(number_of_sides):
  11.   first_roll = randint(1, number_of_sides)
  12.   second_roll = randint(1, number_of_sides)
  13.   max_val = number_of_sides * 2
  14.   print "The maximum possible value is: %d" % max_val
  15.  
  16. if guess > max_val:
  17.   print "Invalid number"
  18.   else:
  19.     print "Rolling..."
  20.     sleep(2)
  21.     print "The 1st roll is: %d" % first_roll
  22.     sleep(1)
  23.     print "The 2nd roll is: %d" % second_roll
  24.     sleep(1)
  25.     total_roll = first_roll + second_roll
  26.      print total_roll
  27.        print "Result..."
  28.         sleep(1)
  29.         if guess > total_roll:
  30.           print "Congrats! You won!"
  31.         else:
  32.           print "Unfortunately, You lost!"
  33.          
  34.          
  35.   roll_dice(6)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement