Team Ai
Apppublic

awacke1/Streamlit-Pyplot-Math-Dice-Game

sourceHugging Facemitupdated 4y agoView on Hugging Face
1likes
app.py41 linesDownload Raw Back to root
1# Streamlit Game of Life2 3#Accept inline code suggestion — Tab4#Dismiss inline code suggestion — Esc5#Show next suggestion — Alt + ] or Option (⌥) + ]6#Show previous suggestion — Alt + [ or Option (⌥) + [7#Trigger suggestion — Alt + \ or Option (⌥) + \8#Open ten suggestions in a separate pane — Ctrl + Enter9 10# Dice Roll Game11 12import streamlit as st13import numpy as np14import pandas as pd15import matplotlib.pyplot as plt16import seaborn as sns17 18st.title('Dice Roll Game')19st.write('This is a dice roll game. Roll the dice and get the highest number')20 21def roll_dice():22    return np.random.randint(1, 7)23 24if st.button('Roll the Dice'):25    roll1 = roll_dice()26    roll2 = roll_dice()27    st.write('You rolled a', roll1, 'and a', roll2)28    if roll1 == roll2:29        st.write('You win! You got a pair of', roll1, 's!')30    else:31        st.write('You lose! Try again!')32 33num_rolls = st.slider('How many times do you want to roll the dice?', 1, 1000, 100)34rolls = [roll_dice() for i in range(num_rolls)]35fig, ax = plt.subplots()36sns.histplot(rolls, kde=False, ax=ax)37ax.set_xlabel('Dice Roll')38ax.set_ylabel('Frequency')39st.pyplot(fig)40 41