Untitled
unknown
plain_text
3 years ago
1.9 kB
5
Indexable
from random import randrange
def input_number(message):
while True:
try:
userInput = int(input(message))
except ValueError:
print("You need to enter a number! Try again.")
continue
else:
return userInput
break
print("**************************************************************************")
sides = int(input_number("How many sides does your dice have? "))
while (sides < 2):
print("Your Dice needs to have at least 2 sides!")
sides = int(input_number("How many sides does your new dice have? "))
rolls_input = int(input_number("How often should it be rolled? "))
while (rolls_input < 1):
print("You need to roll at least once!")
rolls_input = int(input_number("How often should your dice be rolled? "))
guess_total = int(input_number("How much will the total be? "))
while (guess_total < rolls_input):
print("You need to guess at least " + str(rolls_input) + "!")
guess_total = int(input_number("How much will the total be? "))
while (guess_total > rolls_input*sides):
print("That guess is to high, you can't go above " + str(rolls_input*sides) + "!")
guess_total = int(input_number("How much will the total be? "))
rolls = 1
total = 0
while (rolls <= rolls_input):
result = randrange(1, (sides+1))
print("I rolled a " + str(sides) + "-sided dice and the result is: " + str(result))
total += result
rolls += 1
print("You guessed: " + str(guess_total) + ". The total is: " + str(total) + ".")
if guess_total < total:
print("You guessed incorrectly and were short by " + str(total - guess_total) + "!")
elif guess_total > total:
print("You guessed incorrectly and were over by " + str(guess_total - total) + "!")
else:
print("Wow! You guessed correctly! Have a cookie.")
print("**************************************************************************")
Editor is loading...