Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def randint(a, b):
- return a + randbelow(b - a + 1)
- def randbelow(n):
- if n <= 0:
- raise ValueError
- k = n.bit_length()
- numbytes = (k + 7) // 8
- while True:
- r = int.from_bytes(random_bytes(numbytes), 'big')
- r >>= numbytes * 8 - k
- if r < n:
- return r
- def random_bytes(n):
- with open('/dev/urandom', 'rb') as file:
- return file.read(n)
- def main():
- print ("Welcome to Roulette. You may place your bet on odd, even or zero"
- "\nif you bet on zero and win , you win 35 times the amount you bet."
- "\nYou can choose Q to quit the game."
- "\nThe game ends automatically if yoy run out of money.\n")
- print ("Please enter the amount you have:\t")
- wheel = 36
- amount = int(input())
- bet = 0
- choice = ""
- wins = 0
- loss = 0
- choices = ['e', 'o', 'z', 'q', 'Q', 'E', 'Z']
- while amount != 0 or choice not in ['Q', 'q']:
- print ("Please enter your choice (Even, Odd, Zero or Quit : ")
- choice = input()
- if choice not in choices:
- print("INVALID INPUT. PLEASE CHECK YOUR INPUT\n")
- return
- if choice in ['Q', 'q']:
- print("Your remaining money is :$ ", amount)
- print("Number of wins : ", wins )
- print("Number of losses : ", loss)
- break
- print ("Enter the amount of bet : ")
- bet = int(input())
- while bet <= 0 or bet > amount:
- if bet <= 0:
- print("Bets must be greater than 0\n")
- print ("Enter the amount of bet : ")
- bet = int(input())
- if bet > amount:
- print("You may not bet more than you have(",amount,")")
- print ("Enter the amount of bet : \t")
- bet = int(input())
- wheel = randint(0, 36)
- print ("The wheel came up with number :", wheel)
- if wheel % 2 == 0 and (choice in ['e', 'E']):
- amount = amount + bet
- wins = wins + 1
- print("You win! You now have $", amount)
- elif wheel % 2 != 0 and (choice in ['o', 'O']):
- amount = amount + bet
- wins = wins + 1
- print("You win! You now have $", amount)
- elif wheel == 0 and choice in ['z', 'Z']:
- amount = amount + (35*bet)
- wins = wins + 1
- print("You win! You now have $", amount)
- else:
- amount = amount - bet
- loss = loss + 1
- print("Sorry, you lose. You now have $", amount)
- if amount == 0:
- print("Your remaining money is $0")
- print("Number of wins : ", wins)
- print("Number of losses : ", loss)
- break
- print ("Thanks for playing")
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement