Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- #beginning balance
- balance = 5
- again = True
- 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():
- return [random.randint(1,6) for _ in range(3)]
- #analyze the roll list
- def AnalyzeRoll(inputRoll):
- inputRoll.sort()
- print('Your roll is: ' + str(inputRoll))
- if inputRoll == [4,5,6] or len(set(inputRoll)) == 1:
- #456 or triple - auto win
- return(-1)
- elif inputRoll[0] == inputRoll[1] or inputRoll[1] == inputRoll[2]:
- if inputRoll[2] == 6 and inputRoll[1] != inputRoll[2]:
- #pair of non 6 and 6 - auto win
- return(-1)
- elif inputRoll[0] == 1 and inputRoll[0] != inputRoll[1]:
- #pair of non 1 and 1 - auto lose
- return(-2)
- elif inputRoll[1] != inputRoll[2]:
- #left pair
- print('Your score is: ' + str(inputRoll[2]))
- again = False
- return(inputRoll[2])
- elif inputRoll[0] != inputRoll[1]:
- #right pair
- print('Your score is: ' + str(inputRoll[0]))
- again = False
- return(inputRoll[0])
- elif inputRoll == [1,2,3]:
- #auto lose 123
- return(-2)
- else:
- #special case code - no valid roll
- return(-3)
- def UpdateScore(score):
- global again
- global playerScore
- global r
- if score == -1:
- print('You win everything!')
- again = False
- elif score == -2:
- print('You lose everything!')
- again = False
- elif score == -3:
- print('Rolling...')
- r = RollDice()
- else:
- r = RollDice()
- r = RollDice()
- while again is True:
- scorecode = AnalyzeRoll(r)
- UpdateScore(scorecode)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement