import ipywidgets as widgets
import markdown
import random
# Generate a secret random number
secret = random.randint(1, 10)
guessed_correctly = False
# Create a slider for the user's guess
slider = widgets.IntSlider(
value=0,
max=10,
description='Slide to Your Guess:',
continuous_update=False,
style={'description_width': 'initial'},
)
# Create an HTML widget to display the output with Markdown formatting
output = widgets.HTML(
value=markdown.markdown("#### The secret number is a number between 1 and 10. Drag the slider to guess."),
placeholder='Output will be displayed here',
disabled=True,
layout=widgets.Layout(width='500px', height='100px', border='none', font_weight='bold', color='black')
)
# Define a function to handle the slider value change
def on_value_change(change):
global guessed_correctly
if not guessed_correctly:
if slider.value == secret:
guessed_correctly = True
output.value = markdown.markdown("## You got it!")
else:
output.value = markdown.markdown("#### Too small") if slider.value < secret else markdown.markdown("#### Too big")
# Create a VBox to hold the slider and output widgets
ui = widgets.VBox([slider, output])
# Bind the on_value_change function to the slider's value event
slider.observe(on_value_change, names='value')
# Assign the VBox to the page variable
page = ui