File size: 1,154 Bytes
0c664d5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Streamlit Game of Life

#Accept inline code suggestion — Tab
#Dismiss inline code suggestion — Esc
#Show next suggestion — Alt + ] or Option (⌥) + ]
#Show previous suggestion — Alt + [ or Option (⌥) + [
#Trigger suggestion — Alt + \ or Option (⌥) + \
#Open ten suggestions in a separate pane — Ctrl + Enter

# Dice Roll Game

import streamlit as st
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

st.title('Dice Roll Game')
st.write('This is a dice roll game. Roll the dice and get the highest number')

def roll_dice():
    return np.random.randint(1, 7)

if st.button('Roll the Dice'):
    roll1 = roll_dice()
    roll2 = roll_dice()
    st.write('You rolled a', roll1, 'and a', roll2)
    if roll1 == roll2:
        st.write('You win! You got a pair of', roll1, 's!')
    else:
        st.write('You lose! Try again!')

num_rolls = st.slider('How many times do you want to roll the dice?', 1, 1000, 100)
rolls = [roll_dice() for i in range(num_rolls)]
fig, ax = plt.subplots()
sns.histplot(rolls, kde=False, ax=ax)
ax.set_xlabel('Dice Roll')
ax.set_ylabel('Frequency')
st.pyplot(fig)