Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3696da7ae4 |
13
docs/day2.md
13
docs/day2.md
@@ -81,8 +81,7 @@ Before we do anything more interesting we're going to have to cover our logical
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
2. We're going to create an app where the user has to guess the weather. We're going to need the python random module to generate random weather conditions.
|
2. We're going to create an app where the user has to guess the weather. We're going to need the python random module to generate random weather conditions. Add the following to the top of the page:
|
||||||
3. Add the following to the top of the page:
|
|
||||||
|
|
||||||
```python
|
```python
|
||||||
import random
|
import random
|
||||||
@@ -92,7 +91,7 @@ Before we do anything more interesting we're going to have to cover our logical
|
|||||||
|
|
||||||
This tells python we intend to use the `random` package
|
This tells python we intend to use the `random` package
|
||||||
|
|
||||||
4. We'll generate 4 weather conditions. Add the following after `import random`
|
3. We'll generate 4 weather conditions. Add the following after `import random`
|
||||||
|
|
||||||
```python
|
```python
|
||||||
warm = random.choice([True, False])
|
warm = random.choice([True, False])
|
||||||
@@ -105,7 +104,7 @@ Before we do anything more interesting we're going to have to cover our logical
|
|||||||
|
|
||||||
random.choice([True, False]) selects either True or False randomly.
|
random.choice([True, False]) selects either True or False randomly.
|
||||||
|
|
||||||
5. Let's print our weather conditions in a cryptic way. Add the following below our variables:
|
4. Let's print our weather conditions in a cryptic way. Add the following below our variables:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
if warm or cold:
|
if warm or cold:
|
||||||
@@ -125,7 +124,7 @@ Before we do anything more interesting we're going to have to cover our logical
|
|||||||
|
|
||||||
This will print weather conditions in pairs to make it more challenging for our users to guess the weather.
|
This will print weather conditions in pairs to make it more challenging for our users to guess the weather.
|
||||||
|
|
||||||
6. Now let's get our user input. Since we have 4 possible weather conditions we'll need 4 "guessing modules". Let's build the first one:
|
5. Now let's get our user input. Since we have 4 possible weather conditions we'll need 4 "guessing modules". Let's build the first one:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
warm_guess = input("Is it warm? (y/n) ")
|
warm_guess = input("Is it warm? (y/n) ")
|
||||||
@@ -141,7 +140,7 @@ Before we do anything more interesting we're going to have to cover our logical
|
|||||||
|
|
||||||
We ask the user if it's warm. If they say 'y' and it is warm we tell them they got it right! If they guess wrong we tell them they are wrong.
|
We ask the user if it's warm. If they say 'y' and it is warm we tell them they got it right! If they guess wrong we tell them they are wrong.
|
||||||
|
|
||||||
7. We'll just repeat the guess module 3 more times for cold, raining, and snowing.
|
6. We'll just repeat the guess module 3 more times for cold, raining, and snowing.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
cold_guess = input("Is it cold? (y/n) ")
|
cold_guess = input("Is it cold? (y/n) ")
|
||||||
@@ -171,7 +170,7 @@ Before we do anything more interesting we're going to have to cover our logical
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
8. Save with ++ctrl++ + S and run your weather app by typing `python weather_app.py`. Try to guess the weather.
|
7. Save with ++ctrl++ + S and run your weather app by typing `python weather_app.py`. Try to guess the weather.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user