From 52f03a1793dfe71c1f4865e84947e1fe31a73a6f Mon Sep 17 00:00:00 2001 From: lulunac27a <100660343+lulunac27a@users.noreply.github.com> Date: Thu, 29 Aug 2024 17:49:07 -0500 Subject: [PATCH] Add more comments --- dicegame.ipynb | 36 ++++++++++++++++++------------------ dicegame_multiply.ipynb | 37 ++++++++++++++++++------------------- 2 files changed, 36 insertions(+), 37 deletions(-) diff --git a/dicegame.ipynb b/dicegame.ipynb index 113b11c..193c119 100644 --- a/dicegame.ipynb +++ b/dicegame.ipynb @@ -141,7 +141,7 @@ " return scores #return list of scores for all players\n", "\n", "\n", - "num_rolls_slider = widgets.IntSlider(\n", + "num_rolls_slider = widgets.IntSlider( #slider to set number of rolls\n", " value=10,\n", " min=1,\n", " max=20,\n", @@ -149,7 +149,7 @@ " description='Rolls:',\n", " continuous_update=False)\n", "\n", - "num_players_slider = widgets.IntSlider(\n", + "num_players_slider = widgets.IntSlider( #slider to set number of players\n", " value=2,\n", " min=1,\n", " max=10,\n", @@ -157,28 +157,28 @@ " description='Players:',\n", " continuous_update=False)\n", "\n", - "change_value = widgets.Button(description='Roll Dice')\n", - "output = widgets.Output()\n", + "change_value = widgets.Button(description='Roll Dice') #button to roll the dice\n", + "output = widgets.Output() #display output widget\n", "\n", - "display(num_rolls_slider, num_players_slider, change_value, output)\n", + "display(num_rolls_slider, num_players_slider, change_value, output) #display widgets\n", "\n", - "def roll_dice(change):\n", + "def roll_dice(change): #function to roll the dice\n", " \"\"\"\n", " Rolls the dice.\n", " \"\"\" \n", " with output:\n", - " clear_output()\n", - " global numRolls, numPlayers\n", - " scores = dice_game(num_rolls_slider.value, num_players_slider.value)\n", - " print(scores)\n", - " return scores\n", - "\n", - "change_value.on_click(roll_dice)\n", - "\n", - "num_rolls_slider.observe(roll_dice, names='rolls')\n", - "num_players_slider.observe(roll_dice, names='players')\n", - "rolls = num_rolls_slider.value\n", - "players = num_players_slider.value\n" + " clear_output() #clear the output\n", + " global numRolls, numPlayers #set number of rolls and number of players to global variables\n", + " scores = dice_game(num_rolls_slider.value, num_players_slider.value) #set result scores to roll the dice and add the rolled dice with various score multipliers\n", + " print(scores) #print the result with scores for all players\n", + " return scores #return the scores list for all players\n", + "\n", + "change_value.on_click(roll_dice) #when roll dice button is clicked, roll the dice\n", + "\n", + "num_rolls_slider.observe(roll_dice, names='rolls') #observe number of rolls slider value\n", + "num_players_slider.observe(roll_dice, names='players') #observe number of players slider value\n", + "rolls = num_rolls_slider.value #set number of rolls based on slider value\n", + "players = num_players_slider.value #set number of players based on slider value\n" ] } ], diff --git a/dicegame_multiply.ipynb b/dicegame_multiply.ipynb index a9d63e0..9875d3d 100644 --- a/dicegame_multiply.ipynb +++ b/dicegame_multiply.ipynb @@ -142,7 +142,7 @@ " return scores #return list of scores for all players\n", "\n", "\n", - "num_rolls_slider = widgets.IntSlider(\n", + "num_rolls_slider = widgets.IntSlider( #slider to set number of rolls\n", " value=10,\n", " min=1,\n", " max=20,\n", @@ -150,7 +150,7 @@ " description='Rolls:',\n", " continuous_update=False)\n", "\n", - "num_players_slider = widgets.IntSlider(\n", + "num_players_slider = widgets.IntSlider( #slider to set number of players\n", " value=2,\n", " min=1,\n", " max=10,\n", @@ -158,28 +158,27 @@ " description='Players:',\n", " continuous_update=False)\n", "\n", - "change_value = widgets.Button(description='Roll Dice')\n", - "output = widgets.Output()\n", + "change_value = widgets.Button(description='Roll Dice') #button to roll the dice\n", + "output = widgets.Output() #display output widget\n", + "display(num_rolls_slider, num_players_slider, change_value, output) #display widgets\n", "\n", - "display(num_rolls_slider, num_players_slider, change_value, output)\n", - "\n", - "def roll_dice(change):\n", + "def roll_dice(change): #function to roll the dice\n", " \"\"\"\n", " Rolls the dice.\n", " \"\"\" \n", " with output:\n", - " clear_output()\n", - " global numRolls, numPlayers\n", - " scores = dice_game(num_rolls_slider.value, num_players_slider.value)\n", - " print(scores)\n", - " return scores\n", - "\n", - "change_value.on_click(roll_dice)\n", - "\n", - "num_rolls_slider.observe(roll_dice, names='rolls')\n", - "num_players_slider.observe(roll_dice, names='players')\n", - "rolls = num_rolls_slider.value\n", - "players = num_players_slider.value" + " clear_output() #clear the output\n", + " global numRolls, numPlayers #set number of rolls and number of players to global variables\n", + " scores = dice_game(num_rolls_slider.value, num_players_slider.value) #set result scores to roll the dice and add the rolled dice with various score multipliers\n", + " print(scores) #print the result with scores for all players\n", + " return scores #return the scores list for all players\n", + "\n", + "change_value.on_click(roll_dice) #when roll dice button is clicked, roll the dice\n", + "\n", + "num_rolls_slider.observe(roll_dice, names='rolls') #observe number of rolls slider value\n", + "num_players_slider.observe(roll_dice, names='players') #observe number of players slider value\n", + "rolls = num_rolls_slider.value #set number of rolls based on slider value\n", + "players = num_players_slider.value #set number of players based on slider value" ] } ],