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: 1. Your First Code/2. Arithmetic.md
+5-1
Original file line number
Diff line number
Diff line change
@@ -4,15 +4,18 @@
4
4
## We Can Do Math!
5
5
That's right, it's time for some numbers work. You can do a bunch of math in Python, and easily see it working. For starters, let's add a new line of code to your
6
6
repl:
7
+
###### Example 2.1
7
8
```python
8
9
print(2+2)
9
10
```
10
11
Run that. What did the console output? I bet it was 4. Was it 4? Dang, I am so good at this. That's right, the print statement accepts numbers and math, too! You can
11
12
combine numbers AND text:
13
+
###### Example 2.2
12
14
```python
13
15
print("The United States has" , 25+25 , "states!")
14
16
```
15
17
But Python can do more than just addition. Let's try a few different operations, shall we? How about we start with the four main **operators**:
18
+
###### Example 2.3
16
19
```python
17
20
print(2+2)
18
21
print(10/2)
@@ -21,6 +24,7 @@ print(10 - 5)
21
24
```
22
25
If you run this code, you may notice that the results are printed, but it's just a bunch of numbers, which are hard to interpret as a reader. Let's add some text
23
26
to the print statement using the skills you learned in the last section in order to make the output more readable:
27
+
###### Example 2.4
24
28
```python
25
29
print("2 + 2 =", 2+2)
26
30
print("10 / 2 =", 10/2)
@@ -32,7 +36,7 @@ and `/` for division. But wait a second, why did the stuff in quotes not evaluat
32
36
in quotes, so they are read by Python as a "string" type. Let's go on to the next section to discuss those. But first, play around with the arithmetic a bit.
33
37
34
38
## Further Explorations
35
-
###### Here's a few things to try on your own to better understand arithmetic in Python:
39
+
###### Here's a few things to try on your own to better understand arithmetic in Python. You can find all of the above examples, as well as solutions to the Further Explorations problems in solutions2.py
36
40
```
37
41
Use the following information for your exploration problems:
0 commit comments