Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
write a python streamlit program which allows two players to play the dice game called Craps.
|
2 |
+
|
3 |
+
import streamlit as st
|
4 |
+
import random
|
5 |
+
|
6 |
+
st.title("Craps Game")
|
7 |
+
|
8 |
+
# player1
|
9 |
+
player1_name = st.text_input("Player 1 name :")
|
10 |
+
st.write("Hi",player1_name,"Let's play Craps")
|
11 |
+
|
12 |
+
# player2
|
13 |
+
player2_name = st.text_input("Player 2 name :")
|
14 |
+
st.write("Hi",player2_name,"Let's play Craps")
|
15 |
+
|
16 |
+
# Craps game
|
17 |
+
st.write("Let's roll the dice")
|
18 |
+
|
19 |
+
# player1
|
20 |
+
player1_roll = random.randint(2,12)
|
21 |
+
st.write(player1_name,"rolled a", player1_roll)
|
22 |
+
|
23 |
+
# player2
|
24 |
+
player2_roll = random.randint(2,12)
|
25 |
+
st.write(player2_name,"rolled a", player2_roll)
|
26 |
+
|
27 |
+
# game result
|
28 |
+
if player1_roll > player2_roll:
|
29 |
+
st.write(player1_name,"wins!")
|
30 |
+
elif player2_roll > player1_roll:
|
31 |
+
st.write(player2_name,"wins!")
|
32 |
+
else:
|
33 |
+
st.write("It's a tie!")
|