Skip to content

Commit 3927b1d

Browse files
committed
second pass edits
1 parent 0190277 commit 3927b1d

File tree

7 files changed

+70
-90
lines changed

7 files changed

+70
-90
lines changed

config.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,18 @@ steps:
7272
- type: gate
7373
left: '%payload.comment.body%'
7474
operator: <
75-
right: 6
75+
right: 3
7676
else:
7777
- type: respond
7878
with: 03-unlucky.md
7979
data:
8080
rollNum: '%payload.comment.body%'
81+
- type: respond
82+
with: 03-input.md
83+
- type: respond
84+
with: 03-lucky.md
85+
data:
86+
rollNum: '%payload.comment.body%'
8187
- type: respond
8288
with: 03-input.md
8389
issue: 3
@@ -93,5 +99,4 @@ steps:
9399
with: 03-complete.md
94100
issue: 3
95101
- type: closeIssue
96-
issue: 3
97-
102+
issue: 3

responses/02-multiple.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import random
3434
dice_rolls = 2
3535
for i in range(0,dice_rolls):
3636
roll = random.randint(1,6)
37-
print(f'You rolled a {roll}')`
37+
print(f'You rolled a {roll}')
3838
```
3939

4040
In most game situations, rolling multiple dice is followed by adding their values together. Let's do that now. In Python, arithmetic can be performed on variables just by using the equivalent mathematical symbols. Want to add two variables together? It's as simple as: `variable_sum = variable_1 + variable_2`. Since our dice values are stored in a single updating variable instead of separate variables, however, we'll have to add the values upon themselves. First, make a variable called dice_sum above the `for` loop, and set it equal to 0:
@@ -59,6 +59,18 @@ It doesn't matter which version you prefer, just go with whichever way is easier
5959
```python
6060
print('You have rolled a total of {dice_sum}')
6161
```
62-
If you save and run the file, you'll now get the values of the two dice rolls and their combined sum. Neat!
62+
Make sure this statement is not indented (since that would include it in the for loop). Overall, your code should look like this:
6363

64-
*[push your code]({{ repoUrl }}/issues/1) to GitHub to continue*
64+
```python
65+
import random
66+
dice_rolls = 2
67+
dice_sum = 0
68+
for i in range(0,dice_rolls):
69+
roll = random.randint(1,6)
70+
dice_sum += roll
71+
print(f'You rolled a {roll}')
72+
print('You have rolled a total of {dice_sum}')
73+
```
74+
If you save and run the file, you'll now get the values of the two dice rolls and their combined sum. Now our code is developing some complexity!
75+
76+
*[Push your code]({{ repoUrl }}/issues/1) to GitHub to continue*

responses/02-variables.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ We'll want to print that variable, too, so let's change the print function to re
1414
print(f'You rolled a {roll}')
1515
```
1616

17-
Run the code again, and it should say `You rolled a 5`. Nice! Now we're getting a number. Go ahead and `push` your code with the output as the comment within `commit` to move on.
18-
19-
A die that only rolls 5's isn't useful though, so let's add in the randomness that dice are used for.
17+
Run the code again, and it should say `You rolled a 5`. Nice! Now we're getting a number. A die that only rolls 5's isn't useful though, so let's add in the randomness that dice are used for.
2018

2119

2220
## Randomizing Variables

responses/03-conditionals.md

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,6 @@
1-
## Adding Conditionals
2-
Now our code is developing some complexity! By adding our variable manipulation into our `for` loop, the code now looks like this:
3-
4-
```python
5-
import random
6-
dice_rolls = 2
7-
dice_sum = 0
8-
for i in range(0,dice_rolls):
9-
roll = random.randint(1,6)
10-
dice_sum += roll
11-
print(f'You rolled a {roll}')
12-
print('You have rolled a total of {dice_sum}')`
13-
```
14-
151
Let's add some flavor to our responses, dependent on how we roll. We can do this by using conditionals. We'll put a command that only triggers if a certain condition is met. For example, let's add "Critical Fail" in the printed statement if the die roll is a one.
162

17-
In Python, we can set this as the criteria by replacing our print statement with:
3+
In Python, we can set this as the criteria by replacing our print statement in the loop with:
184

195
```python
206
if roll == 1:
@@ -37,4 +23,22 @@ elif roll == 6:
3723
print(f'You rolled a {roll}! Critical Success!')
3824
```
3925

26+
With the conditionals added, your code should look something like this:
27+
28+
```python
29+
import random
30+
dice_rolls = 2
31+
dice_sum = 0
32+
for i in range(0,dice_rolls):
33+
roll = random.randint(1,6)
34+
dice_sum += roll
35+
if roll == 1:
36+
print(f'You rolled a {roll}! Critical Fail')
37+
elif roll == 6:
38+
print(f'You rolled a {roll}! Critical Success!')
39+
else:
40+
print(f'You rolled a {roll}')
41+
print(f'You have rolled a total of {dice_sum}')
42+
```
43+
4044
Leave a comment with the *number of rolls* it took to get a Critical Success.

responses/03-input.md

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,3 @@
1-
Wow, it only took {{ rollNum }} rolls? 🤩 You must be lucky! 🍀
2-
3-
With the conditionals added, your code should look something like this:
4-
5-
```python
6-
import random
7-
dice_rolls = 2
8-
dice_sum = 0
9-
for i in range(0,dice_rolls):
10-
roll = random.randint(1,6)
11-
dice_sum += roll
12-
if roll == 1:
13-
print(f'You rolled a {roll}! Critical Fail')
14-
elif roll == 6:
15-
print(f'You rolled a {roll}! Critical Success!')
16-
else:
17-
print(f'You rolled a {roll}')
18-
print(f'You have rolled a total of {dice_sum}')
19-
```
20-
211
We have a working dice roller right now! It's useful for a very specific situation: rolling two six-sided dice. What if we want to change the number of dice we roll? We can manually edit the code each time, but there's a better way to do this: adding a user `input`.
222

233
Instead of having `dice_rolls` set to a specific value, let's set it equal to:
@@ -33,12 +13,35 @@ Tabletop games use dice with all number of sides so it'll be useful to add a use
3313
dice_size = int(input('How many sides are the dice?'))
3414
```
3515

36-
When changing a value we had assumed to be a specific number previously, we need to make sure the rest of our code still makes sense. All dice start with one, so our `if` statement regarding one still makes sense. Our `elif` statement regarding six doesn't though, as it is no longer guaranteed to be the highest number. Let's make it so our "Critical Success" line is printed to whatever the highest number of our desired dice is. The highest number a dice can roll is the same as the number of sides, so we just to replace our `elif` statement with:
16+
Change the max value of our roll like this
17+
```python
18+
roll = random.randint(1,dice_size)
19+
```
20+
21+
When changing a value we had assumed to be a specific number previously, we need to make sure the rest of our code still makes sense. All dice start with one, so our `if` statement regarding one still makes sense. Our `elif` statement regarding six doesn't though, as it is no longer guaranteed to be the highest number. Let's make it so our "Critical Success" line is printed to whatever the highest number of our desired dice is. The highest number a dice can roll is the same as the number of sides, so we just to replace our `elif` statement with:
3722

3823
```python
3924
elif roll == dice_size:
4025
```
4126

4227
Try it out! Now you can manually input the number of dice and number of sides on the dice knowing that the `Critical Success!` line will realign accordingly.
4328

44-
*[push your code]({{ repoUrl }}/issues/1) to GitHub to finish the course!*
29+
Your final code should look like this:
30+
31+
```python
32+
import random
33+
dice_rolls = int(input('How many dice would you like to roll?'))
34+
dice_size = int(input('How many sides are the dice?'))
35+
dice_sum = 0
36+
for i in range(0,dice_rolls):
37+
roll = random.randint(1,dice_size)
38+
dice_sum += roll
39+
if roll == 1:
40+
print(f'You rolled a {roll}! Critical Fail')
41+
elif roll == dice_size:
42+
print(f'You rolled a {roll}! Critical Success!')
43+
else:
44+
print(f'You rolled a {roll}')
45+
print('You have rolled a total of {dice_sum}')
46+
```
47+
*[Push your code]({{ repoUrl }}/issues/1) to GitHub to finish the course!*

responses/03-lucky.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Wow, it only took {{ rollNum }} rolls? 🤩 You must be lucky! 🍀

responses/03-unlucky.md

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1 @@
1-
Wow, it took {{ rollNum }} rolls? 😮 That is {{ rollNum/6 }} longer than it should have taken! Oh well, you don't need good luck if you have crazy python skills! 😎 🐍
2-
3-
With the conditionals added, your code should look something like this:
4-
5-
```python
6-
import random
7-
dice_rolls = 2
8-
dice_sum = 0
9-
for i in range(0,dice_rolls):
10-
roll = random.randint(1,6)
11-
dice_sum += roll
12-
if roll == 1:
13-
print(f'You rolled a {roll}! Critical Fail')
14-
elif roll == 6:
15-
print(f'You rolled a {roll}! Critical Success!')
16-
else:
17-
print(f'You rolled a {roll}')
18-
print(f'You have rolled a total of {dice_sum}')
19-
```
20-
21-
We have a working dice roller right now! It's useful for a very specific situation: rolling two six-sided dice. What if we want to change the number of dice we roll? We can manually edit the code each time, but there's a better way to do this: adding a user `input`.
22-
23-
Instead of having `dice_rolls` set to a specific value, let's set it equal to:
24-
```python
25-
int(input('How many dice would you like to roll?'))
26-
```
27-
28-
Running the code will give a prompt with that question and we can input our desired number of dice. One thing to note: the value a user inputs defaults to a `str` type and we need it to be a whole number, or an `int` in Python; that's why we encompass the `input` command in an `int()`. Try it out!
29-
30-
Tabletop games use dice with all number of sides so it'll be useful to add a user input for that too. Below where you set `dice_rolls` add this line:
31-
32-
```python
33-
dice_size = int(input('How many sides are the dice?'))
34-
```
35-
36-
When changing a value we had assumed to be a specific number previously, we need to make sure the rest of our code still makes sense. All dice start with one, so our `if` statement regarding one still makes sense. Our `elif` statement regarding six doesn't though, as it is no longer guaranteed to be the highest number. Let's make it so our "Critical Success" line is printed to whatever the highest number of our desired dice is. The highest number a dice can roll is the same as the number of sides, so we just to replace our `elif` statement with:
37-
38-
```python
39-
elif roll == dice_size:
40-
```
41-
42-
Try it out! Now you can manually input the number of dice and number of sides on the dice knowing that the `Critical Success!` line will realign accordingly.
43-
44-
*[push your code]({{ repoUrl }}/issues/1) to GitHub to finish the course!*
1+
Wow, it took {{ rollNum }} rolls? 😮 That is {{ rollNum/3 }} times longer than it should have taken! Oh well, you don't need good luck if you have crazy python skills! 😎 🐍

0 commit comments

Comments
 (0)