Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.87 KB | None | 0 0
  1. def randint(a, b):
  2.     return a + randbelow(b - a + 1)
  3.  
  4. def randbelow(n):
  5.     if n <= 0:
  6.         raise ValueError
  7.     k = n.bit_length()
  8.     numbytes = (k + 7) // 8
  9.     while True:
  10.         r = int.from_bytes(random_bytes(numbytes), 'big')
  11.         r >>= numbytes * 8 - k
  12.         if r < n:
  13.             return r
  14.  
  15. def random_bytes(n):
  16.     with open('/dev/urandom', 'rb') as file:
  17.         return file.read(n)
  18.  
  19.  
  20. def main():
  21.     print ("Welcome to Roulette. You may place your bet on odd, even or zero"
  22.             "\nif you bet on zero and win , you win 35 times the amount you bet."
  23.             "\nYou can choose Q to quit the game."
  24.             "\nThe game ends automatically if yoy run out of money.\n")
  25.  
  26.     print ("Please enter the amount you have:\t")
  27.     wheel = 36
  28.     amount = int(input())
  29.     bet = 0
  30.     choice = ""
  31.     wins = 0
  32.     loss = 0
  33.     choices = ['e', 'o', 'z', 'q', 'Q', 'E', 'Z']
  34.  
  35.     while amount != 0 or choice not in ['Q', 'q']:
  36.         print ("Please enter your choice (Even, Odd, Zero or Quit : ")
  37.         choice = input()
  38.  
  39.         if choice not in choices:
  40.             print("INVALID INPUT. PLEASE CHECK YOUR INPUT\n")
  41.             return
  42.         if choice in ['Q', 'q']:
  43.             print("Your remaining money is :$ ", amount)
  44.             print("Number of wins : ", wins )
  45.             print("Number of losses : ", loss)
  46.             break
  47.  
  48.         print ("Enter the amount of bet : ")
  49.         bet = int(input())
  50.  
  51.         while bet <= 0 or bet > amount:
  52.             if bet <= 0:
  53.                 print("Bets must be greater than 0\n")
  54.                 print ("Enter the amount of bet : ")
  55.                 bet = int(input())
  56.             if bet > amount:
  57.                 print("You may not bet more than you have(",amount,")")
  58.                 print ("Enter the amount of bet : \t")
  59.                 bet = int(input())
  60.         wheel = randint(0, 36)
  61.         print ("The wheel came up with number :", wheel)
  62.  
  63.         if wheel % 2 == 0 and (choice in ['e', 'E']):
  64.             amount = amount + bet
  65.             wins = wins + 1
  66.             print("You win! You now have $", amount)
  67.         elif wheel % 2 != 0 and (choice in ['o', 'O']):
  68.             amount = amount + bet
  69.             wins = wins + 1
  70.             print("You win! You now have $", amount)
  71.         elif wheel == 0 and choice in ['z', 'Z']:
  72.             amount = amount + (35*bet)
  73.             wins = wins + 1
  74.             print("You win! You now have $", amount)
  75.         else:
  76.             amount = amount - bet
  77.             loss = loss + 1
  78.             print("Sorry, you lose. You now have $", amount)
  79.  
  80.             if amount == 0:
  81.                 print("Your remaining money is $0")
  82.                 print("Number of wins : ", wins)
  83.                 print("Number of losses : ", loss)
  84.                 break
  85.  
  86.     print ("Thanks for playing")
  87.  
  88. if __name__ == "__main__":
  89.  
  90.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement