Guest User

RollDaDice.py

a guest
Jan 8th, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.28 KB | None | 0 0
  1. #pylint:disable=W0312
  2. #python 3.6
  3. from random import randint
  4. import math
  5.  
  6. balances = 100
  7. guessNr   = ("-- Enter a number from 1 to 6! -- \n")
  8. makeBet   = ("Enter a bet! Your balance: {}\n".format(balances))
  9.  
  10.  
  11. #### FUNC START ####
  12. def diceRoll(guess, bet):
  13.  
  14. ### EXCEPTION HANDLING
  15.     try:
  16.         rollAgain = ("Do you want to play again? Y/N? \n")
  17.     except TypeError:
  18.         print("Error! ", rollAgain)
  19.     try:
  20.         guess   = int(guess)
  21.         bet     = int(bet)
  22.     except ValueError: 
  23.         print("Wrong values submitted! Try again...")
  24.         diceRoll(input(guessNr), input(makeBet))   
  25.        
  26. ### VARS
  27.     balance         = balances
  28.     roll                  = randint(1,6)
  29.     continueRoll = False
  30.     gameLost     = False
  31.     gameWon     = False
  32.  
  33.     ## print("Your balance is: {}$".format(balance)) ~ IGNORE THIS ~
  34.  
  35.  
  36. ### CHECK FOR FUNDS AND VALID INPUTS   
  37.     if (bet > balance):
  38.         print("Insufficient funds.")
  39.         continueRoll = False   
  40.         diceRoll(input(guessNr), input(makeBet))
  41.         #
  42.     elif (guess > 6 or guess <= 0):
  43.         print("Wrong guess submitted.")
  44.         continueRoll = False   
  45.         diceRoll(input(guessNr), input(makeBet))   
  46.            
  47. ### IF ABOVE IS OK, CONTINUE ###
  48.     if (bet <= balance and guess <= 6 or guess > 0):
  49.         betBalance = balance - bet         
  50.         print("\nYou bet {}$. Your new balance is: {}".format(bet,      betBalance))
  51.         continueRoll = True
  52.  
  53. ### IF PLAYER WINS ###
  54.     if (roll == guess and continueRoll):
  55.         gameWon = True
  56.         winPrize = (bet * 1.75)
  57.         newBalance = balance + winPrize
  58.         #
  59.         print("\nYOU WIN {}$!".format(winPrize))
  60.         print("You guessed: {} - The roll was {}!\n".format(guess, roll))
  61.         print("-- Your balance is now {}$ -- \n".format(newBalance))
  62.         choice = input(rollAgain).title()
  63.  
  64. ### IF PLAYER LOSE ###
  65.     elif (roll != guess):
  66.         gameLost = True
  67.         newBalance = balance - bet
  68.         #
  69.         print("\nYOU LOSE {}$".format(bet))
  70.         print("The roll was: {} - You guessed: {}.".format(roll,guess))
  71.         print("-- Your balance is now {}$ --\n".format(newBalance))
  72.         choice = input(rollAgain).title()
  73.        
  74. ### ASK PLAYER TO PLAY AGAIN ###
  75.     while (gameLost == True or gameWon == True):
  76.         if (choice == "Yes" or choice == "Y"):
  77.             print("New round! Your balance is {}$".format(newBalance))
  78.             diceRoll(input(guessNr), input(makeBet))
  79.             #
  80.         elif (choice != "No" or choice != "N"):
  81.             print("GAME OVER !")
  82.             return
  83.         return
  84.     return newBalance
  85.  
  86. ### CALL FUNCTION ###
  87. diceRoll(input(guessNr), input(makeBet))
Advertisement
Add Comment
Please, Sign In to add comment