-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroll_dice.py
More file actions
45 lines (30 loc) · 1005 Bytes
/
roll_dice.py
File metadata and controls
45 lines (30 loc) · 1005 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import ctypes
# Load the shared library
casino = ctypes.CDLL('./roll_dice.so') # Update the path if necessary
# Define the C function prototype
casino.rollDice.restype = ctypes.c_int
def roll_dice():
return casino.rollDice()
def play_game():
balance = 100 # Initial balance
print("Welcome to the Casino!")
while balance > 0:
print("\nYour current balance:", balance)
bet = int(input("Enter your bet (0 to quit): "))
if bet == 0:
break
if bet > balance:
print("Insufficient balance. Please place a lower bet.")
continue
dice_roll = roll_dice()
print("Dice roll:", dice_roll)
if dice_roll == 6:
print("Congratulations! You won!")
balance += bet
else:
print("Sorry, you lost.")
balance -= bet
print("\nGame over. Your final balance:", balance)
print("Thank you for playing!")
if __name__ == '__main__':
play_game()