awacke1's picture
Update app.py
9083192
raw
history blame
No virus
890 Bytes
import random
import streamlit as st
import plotly.express as px
# Set page title
st.set_page_config(page_title="Dice-Roll-Treemap-Plotly - d100 Dice Roll Treemap Chart")
# Define function to roll a d100 dice
def roll_dice():
return random.randint(1, 100)
# Roll dice 1000 times and store results
rolls = [roll_dice() for _ in range(1000)]
# Convert rolls to counts and create dictionary
counts = {}
for roll in rolls:
if roll not in counts:
counts[roll] = 1
else:
counts[roll] += 1
# Create Plotly treemap chart using counts
fig = px.treemap(
names=[f":game_die: {roll}" for roll in counts.keys()],
parents=["Dice Rolls" for _ in counts.keys()],
values=list(counts.values()),
color=list(counts.keys()),
color_continuous_scale="YlOrRd",
title="d100 Dice Roll Treemap Chart",
)
# Render chart in Streamlit app
st.plotly_chart(fig)