Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- #beginning balance
- balance = 5
- playerScore = 0
- playerRoll = [0,0,0]
- response = input('Are you ready to play ceelo?: ')
- if response=='yes' or response=='y':
- print('You have $' + str(balance))
- #runs while this condition is true & until it is broken by 'break'
- while True:
- bet = input('Enter your bet: ')
- #try loop is accounting for ValueError - in case the user inputs something besides a number
- try:
- if int(bet) <= 5:
- print('Your bet is $' + str(bet))
- balance-=int(bet)
- break
- elif int(bet) < 1:
- print('You have to bet something!')
- else:
- print("You can't bet that much.")
- except ValueError:
- print('Enter a number please.')
- print('You have $' + str(balance) + ' left')
- #dice roll function
- def RollDice():
- roll = [random.randint(1,6) for _ in range(3)]
- roll.sort()
- return roll
- #analyze the roll list
- def AnalyzeRoll(inputRoll):
- while True:
- if (inputRoll[2] == 6 and inputRoll[0] == inputRoll[1]) or inputRoll == [4,5,6]:
- print('Congrats! You take everything.')
- break
- #auto lose
- elif (inputRoll[0] == 1 and inputRoll[1] == inputRoll[2]) or inputRoll == [1,2,3]:
- print('Oops! You lose everything.')
- break
- #set point value
- else:
- if inputRoll[0] == inputRoll[1]:
- playerScore = inputRoll[2]
- else:
- playerScore = inputRoll[0]
- print("Your score is: " + str(playerScore))
- break
- #assinging our roll to our global playerRoll variable
- #only break out of this loop when we have a valid roll
- while True:
- playerRoll = RollDice()
- print(playerRoll)
- if playerRoll[0]==playerRoll[1] or playerRoll[1]==playerRoll[2]:
- break
- else:
- playerRoll = RollDice()
- AnalyzeRoll(playerRoll)
Add Comment
Please, Sign In to add comment