Skip to content

Commit

Permalink
Add more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
lulunac27a committed Aug 29, 2024
1 parent 38407c8 commit 52f03a1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 37 deletions.
36 changes: 18 additions & 18 deletions dicegame.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -141,44 +141,44 @@
" 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",
" step=1,\n",
" 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",
" step=1,\n",
" 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"
]
}
],
Expand Down
37 changes: 18 additions & 19 deletions dicegame_multiply.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -142,44 +142,43 @@
" 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",
" step=1,\n",
" 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",
" step=1,\n",
" 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"
]
}
],
Expand Down

0 comments on commit 52f03a1

Please sign in to comment.