Dice roll - Push Up machine

mail@pastecode.io avatar
unknown
python
2 years ago
2.3 kB
1
Indexable
Never
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("**************************************************************************")

#getting inputs + checking if inputs are a) integers & b) logical
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? "))

# setting base levels
rolls = 1
total = 0

# roll dice
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

# give out results & let user know if guess was too high, too low or just right
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) + "! Do " + str(round((total-guess_total)*((guess_total/sides)+rolls))) + " Push-Ups or play again!")
elif guess_total > total:
    print("You guessed incorrectly and were over by " + str(guess_total - total) + "! Do " + str(round((guess_total-total)*((guess_total/sides)+rolls))) + " Push-Ups or play again!")
else:
    print("Wow! You guessed correctly! Have a cookie.")

print("**************************************************************************")