You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Day-2/README.md
+5-5Lines changed: 5 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -10,13 +10,13 @@ Open the starter file: [silly sentence generator.py](silly sentence generator.py
10
10
11
11
Up until now, we've stored things in one variable at a time. A list is a way to collect multiple values in one variable. Let's make a list:
12
12
13
-
```
13
+
```python
14
14
>>> grocery_list = ["apples","bananas","a pet chicken"]
15
15
```
16
16
17
17
We can look at specific items in the list with an *index*, and indexes start from zero.
18
18
19
-
```
19
+
```python
20
20
>>>print grocery_list[0]
21
21
apples
22
22
```
@@ -25,7 +25,7 @@ apples
25
25
26
26
We can use the random module to create random numbers:
27
27
28
-
```
28
+
```python
29
29
import random
30
30
random.randint(0,5)
31
31
```
@@ -35,7 +35,7 @@ A module is something extra in Python that lets you go beyond what Python lets y
35
35
####The `random_word` Function
36
36
The `random_word` function picks a random index from 0 to the last item in the list. Then, it finds the word with that index, and hands it back:
37
37
38
-
```
38
+
```python
39
39
#this function is given a list of words and selects one at random
40
40
defrandom_word(list_of_words):
41
41
number_of_words =len(list_of_words) #get the length of the words list
@@ -68,7 +68,7 @@ Be sure to insert the word "the" in the right places. What sentences can you ma
68
68
####`random.choice`
69
69
We just wrote a function to pick a random word from a list of words. However, the `random` module already gives us a way to do this. We can use `random.choice` to write a new version of `random_word`:
0 commit comments