Advertisement
lil_blizzard

Untitled

Aug 2nd, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.41 KB | None | 0 0
  1. import random
  2.  
  3. #beginning balance
  4. balance = 5
  5.  
  6. again = True
  7.  
  8. response = input('Are you ready to play ceelo?: ')
  9.  
  10. if response=='yes' or response=='y':
  11.     print('You have $' + str(balance))
  12.  
  13. #runs while this condition is true & until it is broken by 'break'
  14. while True:
  15.  
  16.     bet = input('Enter your bet: ')
  17.     #try loop is accounting for ValueError - in case the user inputs something besides a number
  18.     try:
  19.         if int(bet) <= 5:
  20.             print('Your bet is $' + str(bet))
  21.             balance-=int(bet)
  22.             break
  23.         elif int(bet) < 1:
  24.             print('You have to bet something!')
  25.         else:
  26.             print("You can't bet that much.")
  27.     except ValueError:
  28.         print('Enter a number please.')
  29.  
  30. print('You have $' + str(balance) + ' left')
  31.  
  32. #dice roll function
  33. def RollDice():
  34.     return [random.randint(1,6) for _ in range(3)]
  35.  
  36. #analyze the roll list
  37. def AnalyzeRoll(inputRoll):
  38.     inputRoll.sort()
  39.     print('Your roll is: ' + str(inputRoll))
  40.     if inputRoll == [4,5,6] or len(set(inputRoll)) == 1:
  41.         #456 or triple - auto win
  42.         return(-1)
  43.     elif inputRoll[0] == inputRoll[1] or inputRoll[1] == inputRoll[2]:
  44.         if inputRoll[2] == 6 and inputRoll[1] != inputRoll[2]:
  45.             #pair of non 6 and 6 - auto win
  46.             return(-1)
  47.         elif inputRoll[0] == 1 and inputRoll[0] != inputRoll[1]:
  48.             #pair of non 1 and 1 - auto lose
  49.             return(-2)
  50.         elif inputRoll[1] != inputRoll[2]:
  51.             #left pair
  52.             print('Your score is: ' + str(inputRoll[2]))
  53.             again = False
  54.             return(inputRoll[2])
  55.         elif inputRoll[0] != inputRoll[1]:
  56.             #right pair
  57.             print('Your score is: ' + str(inputRoll[0]))
  58.             again = False
  59.             return(inputRoll[0])
  60.     elif inputRoll == [1,2,3]:
  61.         #auto lose 123
  62.         return(-2)
  63.     else:
  64.         #special case code - no valid roll
  65.         return(-3)
  66.  
  67. def UpdateScore(score):
  68.     global again
  69.     global playerScore
  70.     global r
  71.  
  72.     if score == -1:
  73.         print('You win everything!')
  74.         again = False
  75.     elif score == -2:
  76.         print('You lose everything!')
  77.         again = False
  78.     elif score == -3:
  79.         print('Rolling...')
  80.         r = RollDice()
  81.     else:
  82.         r = RollDice()
  83.  
  84. r = RollDice()
  85. while again is True:
  86.     scorecode = AnalyzeRoll(r)
  87.     UpdateScore(scorecode)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement