Skip to content

Commit 12e2c2d

Browse files
adamdgithub-learning-lab[bot]
authored andcommitted
Copy edits and code tweaks
1 parent 486ba75 commit 12e2c2d

File tree

7 files changed

+64
-56
lines changed

7 files changed

+64
-56
lines changed

config.yml

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
title: Intermediate Python
2-
tagline: Create a REST api with Node.js, Express.js, and MongoDB
2+
tagline: 'Random numbers, variables, and conditionals'
33
description: Learn how to create a dice-rolling app with Python!
44
tags:
55
- Python
6-
76
template:
87
name: intermediate-python-course
98
repo: intermediate-python-course-template
@@ -12,84 +11,78 @@ before:
1211
- type: createIssue
1312
title: Set up your project
1413
body: 01-setup.md
15-
1614
steps:
1715
- title: Set up your project
1816
description: Introduces the project and how to set it up
1917
event: issue_comment
20-
link: "{{ repoUrl }}/issues/1"
21-
actions:
18+
link: '{{ repoUrl }}/issues/1'
19+
actions:
2220
- type: respond
2321
with: 01-running.md
2422
issue: 1
2523
data:
2624
game: '%payload.comment.body%'
27-
2825
- title: Running a Python program
2926
description: Run a python program with a main method
3027
event: push
31-
link: "{{ repoUrl }}/issues/1"
32-
actions:
28+
link: '{{ repoUrl }}/issues/1'
29+
actions:
3330
- type: respond
3431
with: 01-complete.md
3532
issue: 1
3633
- type: closeIssue
3734
issue: 1
3835
- type: createIssue
39-
title: Using Variables
36+
title: Using Variables
4037
body: 02-variables.md
41-
4238
- title: Using Variables
4339
description: Define variables with random input to simulate a die-roll
4440
event: issue_comment
45-
link: "{{ repoUrl }}/issues/2"
46-
actions:
41+
link: '{{ repoUrl }}/issues/2'
42+
actions:
4743
- type: respond
4844
with: 02-multiple.md
4945
issue: 2
50-
data:
46+
data:
5147
roll: '%payload.comment.body%'
52-
5348
- title: Rolling multiple Dice
5449
description: Roll multiple dice and add their results
5550
event: push
56-
link: "{{ repoUrl }}/issues/2"
51+
link: '{{ repoUrl }}/issues/2'
5752
actions:
5853
- type: respond
5954
with: 02-complete.md
6055
issue: 2
6156
- type: closeIssue
6257
issue: 2
6358
- type: createIssue
64-
title: Adding Conditionals
59+
title: Adding Conditionals
6560
body: 03-conditionals.md
66-
6761
- title: Adding Conditionals
6862
description: Add some flavor to your responses with conditionals
6963
event: issue_comment
70-
link: "{{ repoUrl }}/issues/3"
71-
actions:
64+
link: '{{ repoUrl }}/issues/3'
65+
actions:
7266
- type: gate
7367
left: '%payload.comment.body%'
7468
operator: <
7569
right: 3
7670
else:
77-
- type: respond
78-
with: 03-unlucky.md
79-
data:
80-
rollNum: '%payload.comment.body%'
71+
- type: respond
72+
with: 03-unlucky.md
73+
data:
74+
rollNum: '%payload.comment.body%'
8175
- type: respond
8276
with: 03-lucky.md
83-
data:
77+
data:
8478
rollNum: '%payload.comment.body%'
85-
8679
- title: Adding User Input
8780
description: Allow users to input the number and size of dice
8881
event: push
89-
link: "{{ repoUrl }}/issues/3"
82+
link: '{{ repoUrl }}/issues/3'
9083
actions:
9184
- type: respond
9285
with: 03-complete.md
9386
issue: 3
9487
- type: closeIssue
95-
issue: 3
88+
issue: 3

responses/01-running.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ def main():
1212
Below that, you'll see an `if` statement calling that function:
1313

1414
```python
15-
`if __name__== "__main__":
16-
main()`
15+
if __name__== "__main__":
16+
main()
1717
```
1818
By doing this, the function `main` will run whenever you run the Python script. As you develop the dice roller, be sure to only manipulate the code within the `main` function; nothing else will need to be changed.
1919

responses/02-multiple.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ We would then have a set of commands it would do for every `i`. We already have
2727

2828
## Manipulating Variables
2929

30-
With a `for` loop implemented, your code takes the form of this:
30+
With a `for` loop implemented, your main function takes this form:
3131

3232
```python
33-
import random
3433
dice_rolls = 2
3534
for i in range(0,dice_rolls):
3635
roll = random.randint(1,6)
@@ -57,20 +56,24 @@ dice_sum += roll
5756

5857
It doesn't matter which version you prefer, just go with whichever way is easier for you to visualize. Finally, let's print out our final value for `dice_sum`. After the `for` loop is finished, type:
5958
```python
60-
print('You have rolled a total of {dice_sum}')
59+
print(f'You have rolled a total of {dice_sum}')
6160
```
62-
Make sure this statement is not indented (since that would include it in the for loop). Overall, your code should look like this:
61+
Make sure this statement is not indented (since that would include it in the for loop). Overall, your main function should look like this:
6362

6463
```python
65-
import random
6664
dice_rolls = 2
6765
dice_sum = 0
6866
for i in range(0,dice_rolls):
6967
roll = random.randint(1,6)
7068
dice_sum += roll
7169
print(f'You rolled a {roll}')
72-
print('You have rolled a total of {dice_sum}')
70+
print(f'You have rolled a total of {dice_sum}')
7371
```
7472
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!
7573

76-
*[Push your code]({{ repoUrl }}/issues/1) to GitHub to continue*
74+
**Push your code** to GitHub to continue:
75+
```
76+
git add dice_roller.py
77+
git commit -m "Now rolling two dice"
78+
git push
79+
```

responses/02-variables.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ To use a package, we'll need to import it. At the top of the file, import the pa
3535
import random
3636
```
3737

38-
In general, it's good practice to import all packages at the beginning of the script. Now let's use that package to randomize our `roll` variable. To get a random integer with the `random` package, we'll want to use the following format:
38+
In general, it's good practice to import all packages at the beginning of the script. Now let's use that package to randomize our `roll` variable.
39+
40+
To get a random integer with the `random` package, we'll update the `roll` line like so:
3941

4042
```python
41-
random.randint(X,Y)
43+
roll = random.randint(1,6)
4244
```
4345

44-
where X and Y are the boundaries of the range you want your random integers to be in. Note that X, the beginning of the range and Y, and the end of the range, are inclusive bounds. Note that X (the beginning of the range) and Y (the end of the range), are inclusive bounds. This means the integers you put as X and Y will be part of possible values. Knowing that, try changing `roll` to equal any integer that is possible to roll on a six-sided die: 1, 2, 3, 4, 5 and 6. There's no need to change anything in the print statement, as we've already tied it to whatever our `roll` variable is.
46+
The `random.randint` function takes two integers as parameters. In this case, since we want to emulate a six-sided die, we want to include the range of results that is possible: 1, 2, 3, 4, 5 and 6. Note that the beginning and the end of the range are inclusive bounds. That is, 1 and 6 are possible values, along with integers between them.
4547

4648
Now run the code and put *the number* you rolled as a comment, and then we'll keep this tutorial *rolling*!

responses/03-conditionals.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ elif roll == 6:
2323
print(f'You rolled a {roll}! Critical Success!')
2424
```
2525

26-
With the conditionals added, your code should look something like this:
26+
With the conditionals added, your main function should look something like this:
2727

2828
```python
29-
import random
3029
dice_rolls = 2
3130
dice_sum = 0
3231
for i in range(0,dice_rolls):

responses/03-lucky.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ We have a working dice roller right now! It's useful for a very specific situati
66

77
Instead of having `dice_rolls` set to a specific value, let's set it equal to:
88
```python
9-
int(input('How many dice would you like to roll?'))
9+
int(input('How many dice would you like to roll? '))
1010
```
1111

1212
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!
1313

1414
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:
1515

1616
```python
17-
dice_size = int(input('How many sides are the dice?'))
17+
dice_size = int(input('How many sides are the dice? '))
1818
```
1919

2020
Change the max value of our roll like this
@@ -30,12 +30,12 @@ elif roll == dice_size:
3030

3131
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.
3232

33-
Your final code should look like this:
33+
Your final main function should look like this:
3434

3535
```python
3636
import random
37-
dice_rolls = int(input('How many dice would you like to roll?'))
38-
dice_size = int(input('How many sides are the dice?'))
37+
dice_rolls = int(input('How many dice would you like to roll? '))
38+
dice_size = int(input('How many sides are the dice? '))
3939
dice_sum = 0
4040
for i in range(0,dice_rolls):
4141
roll = random.randint(1,dice_size)
@@ -46,6 +46,12 @@ for i in range(0,dice_rolls):
4646
print(f'You rolled a {roll}! Critical Success!')
4747
else:
4848
print(f'You rolled a {roll}')
49-
print('You have rolled a total of {dice_sum}')
49+
print(f'You have rolled a total of {dice_sum}')
5050
```
51-
*[Push your code]({{ repoUrl }}/issues/1) to GitHub to finish the course!*
51+
52+
**Push your code** to GitHub to continue:
53+
```
54+
git add dice_roller.py
55+
git commit -m "Tutorial complete"
56+
git push
57+
```

responses/03-unlucky.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ We have a working dice roller right now! It's useful for a very specific situati
66

77
Instead of having `dice_rolls` set to a specific value, let's set it equal to:
88
```python
9-
int(input('How many dice would you like to roll?'))
9+
int(input('How many dice would you like to roll? '))
1010
```
1111

1212
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!
1313

1414
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:
1515

1616
```python
17-
dice_size = int(input('How many sides are the dice?'))
17+
dice_size = int(input('How many sides are the dice? '))
1818
```
1919

2020
Change the max value of our roll like this
@@ -30,12 +30,11 @@ elif roll == dice_size:
3030

3131
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.
3232

33-
Your final code should look like this:
33+
Your final main function should look like this:
3434

3535
```python
36-
import random
37-
dice_rolls = int(input('How many dice would you like to roll?'))
38-
dice_size = int(input('How many sides are the dice?'))
36+
dice_rolls = int(input('How many dice would you like to roll? '))
37+
dice_size = int(input('How many sides are the dice? '))
3938
dice_sum = 0
4039
for i in range(0,dice_rolls):
4140
roll = random.randint(1,dice_size)
@@ -46,6 +45,12 @@ for i in range(0,dice_rolls):
4645
print(f'You rolled a {roll}! Critical Success!')
4746
else:
4847
print(f'You rolled a {roll}')
49-
print('You have rolled a total of {dice_sum}')
48+
print(f'You have rolled a total of {dice_sum}')
5049
```
51-
*[Push your code]({{ repoUrl }}/issues/1) to GitHub to finish the course!*
50+
51+
**Push your code** to GitHub to continue:
52+
```
53+
git add dice_roller.py
54+
git commit -m "Tutorial complete"
55+
git push
56+
```

0 commit comments

Comments
 (0)