Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pylint:disable=W0312
- #python 3.6
- from random import randint
- import math
- balances = 100
- guessNr = ("-- Enter a number from 1 to 6! -- \n")
- makeBet = ("Enter a bet! Your balance: {}\n".format(balances))
- #### FUNC START ####
- def diceRoll(guess, bet):
- ### EXCEPTION HANDLING
- try:
- rollAgain = ("Do you want to play again? Y/N? \n")
- except TypeError:
- print("Error! ", rollAgain)
- try:
- guess = int(guess)
- bet = int(bet)
- except ValueError:
- print("Wrong values submitted! Try again...")
- diceRoll(input(guessNr), input(makeBet))
- ### VARS
- balance = balances
- roll = randint(1,6)
- continueRoll = False
- gameLost = False
- gameWon = False
- ## print("Your balance is: {}$".format(balance)) ~ IGNORE THIS ~
- ### CHECK FOR FUNDS AND VALID INPUTS
- if (bet > balance):
- print("Insufficient funds.")
- continueRoll = False
- diceRoll(input(guessNr), input(makeBet))
- #
- elif (guess > 6 or guess <= 0):
- print("Wrong guess submitted.")
- continueRoll = False
- diceRoll(input(guessNr), input(makeBet))
- ### IF ABOVE IS OK, CONTINUE ###
- if (bet <= balance and guess <= 6 or guess > 0):
- betBalance = balance - bet
- print("\nYou bet {}$. Your new balance is: {}".format(bet, betBalance))
- continueRoll = True
- ### IF PLAYER WINS ###
- if (roll == guess and continueRoll):
- gameWon = True
- winPrize = (bet * 1.75)
- newBalance = balance + winPrize
- #
- print("\nYOU WIN {}$!".format(winPrize))
- print("You guessed: {} - The roll was {}!\n".format(guess, roll))
- print("-- Your balance is now {}$ -- \n".format(newBalance))
- choice = input(rollAgain).title()
- ### IF PLAYER LOSE ###
- elif (roll != guess):
- gameLost = True
- newBalance = balance - bet
- #
- print("\nYOU LOSE {}$".format(bet))
- print("The roll was: {} - You guessed: {}.".format(roll,guess))
- print("-- Your balance is now {}$ --\n".format(newBalance))
- choice = input(rollAgain).title()
- ### ASK PLAYER TO PLAY AGAIN ###
- while (gameLost == True or gameWon == True):
- if (choice == "Yes" or choice == "Y"):
- print("New round! Your balance is {}$".format(newBalance))
- diceRoll(input(guessNr), input(makeBet))
- #
- elif (choice != "No" or choice != "N"):
- print("GAME OVER !")
- return
- return
- return newBalance
- ### CALL FUNCTION ###
- diceRoll(input(guessNr), input(makeBet))
Advertisement
Add Comment
Please, Sign In to add comment