Advertisement
Guest User

Untitled

a guest
Jun 13th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #this program is a game that rolls a dice and allows the user to guess the value that the dice will produce.
  2. from random import randint
  3. from time import sleep
  4. number_of_sides = 6
  5. def get_user_guess():
  6. guess = int(raw_input("guess a number:"))
  7. return guess
  8. def roll_dice(number_of_sides):
  9. first_roll = randint(1, number_of_sides)
  10. second_roll = randint(1, number_of_sides)
  11. max_val = number_of_sides * 2
  12. print "The maximum possible value is: %d" % max_val
  13. guess = get_user_guess()
  14. if guess > max_val:
  15. print "invalid"
  16. roll_dice(6)
  17. else:
  18. print "Rolling...."
  19. sleep(2)
  20. print "The 1st roll is: %d" % first_roll
  21. sleep(1)
  22. print "The 2nd roll is: %d" % second_roll
  23. sleep(1)
  24. total_roll = first_roll + second_roll
  25. print total_roll
  26. print "Result...."
  27. sleep(1)
  28. if guess == total_roll:
  29. print "You have won!!"
  30. else:
  31. print "you lost!"
  32. roll_dice(6)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement