Skip to content

Commit

Permalink
lesson updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Latkecrszy committed Jul 3, 2021
1 parent 0c868d0 commit 744f2e2
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 26 deletions.
10 changes: 5 additions & 5 deletions lessons/builtins.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
You may have noticed that we've been using `print()` in our previous code.
You didn't know it at the time, but that was your first time using a builtin!
A builtin is a function that is built into Python and can be used automatically. So what is a function?
A function is a block of code takes input and then gives output, and can be used multiple times.
A function is a block of code that takes input and then gives output, and can be used multiple times.
`print()` is an example of a function. The input it takes, called parameters, goes inside the parentheses.
This is why to print out a variable, we put its name inside the parentheses after `print`.
We'll learn how to make our own functions with input and output later, but right now we're dealing only with the builtins.
Expand All @@ -13,15 +13,15 @@ Of course! There are many builtins in Python, about 69, and they all serve a uni
Besides `print()`, you'll also learn about `input()`, `min()`, `max()`, `str()`, `int()`, and more.
Right now, we're going to learn `input()`.
`input()` is a bit of an outlier compared to other builtin functions, because it has two forms of output instead of just one.
It both prints to the console and returns a value in the code. So, how does it do this?
It both prints to the console (box on the bottom right) and returns a value in the code. So, how does it do this?
The purpose of `input()` is to take input from a user.
So whatever we pass into its parentheses will be printed into the console (just like `print()`), and it will wait for a user response.
Whatever we pass into its parentheses will be printed into the console (just like `print()`), and it will wait for a user response.
Once the user types something in and presses enter, that value will be given back in the code.
Here's an example: Let's say I have the program `name = input("What is your name?")`.
With this, I am creating a variable called `name` and setting it equal to whatever the user types in.
First, `"What is your name?"` would be printed in the console (displayed in the bottom right box).
Then, the program waits for the user to type something in and press enter.
Finally, the text that the user typed in is stored in the variable `name`, because that's what I defined it as.
Then, the program waits for a user to type something in and press enter.
Finally, the text that the user typed in is stored in the variable `name`, because that's the name I gave it.
This concept can be confusing at first, but once you see it in action it becomes more clear what it does.

## You try!
Expand Down
2 changes: 1 addition & 1 deletion lessons/ints_and_floats.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ For example, `20` is an integer, but `20.5` is a float.

## Can a whole number be a float?
Absolutely. `20` may be an integer, but `20.0` is a perfectly valid float.
This is true for any integer, adding `.0` onto the end of it turns it into a float.
This is true for any integer - adding `.0` onto the end of it turns it into a float.
However, decimals can never be integers. There is no way to turn `20.5` into an integer without rounding up or down.

## How do I round a number in Python?
Expand Down
21 changes: 12 additions & 9 deletions lessons/math.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Math in Python
## How do I do math?
In python, math is very similar to anywhere else. It follows order of operations (PEMDAS),
you can prioritize operations with parenthesis, and most of the symbols are the same.
## How do I do math in Python?
In Python, math is very similar to anywhere else. It follows order of operations (PEMDAS),
you can prioritize operations with parentheses, and most of the symbols are the same.
That being said, there are some definitively different symbols. Let this serve as a guide:
- `+` is addition. Example: `x = 7 + 7`
- `-` is subtraction. Example: `x = 7 - 7`
Expand All @@ -11,14 +11,14 @@ That being said, there are some definitively different symbols. Let this serve a
- `**` is exponents (powers). Example: `x = 7 ** 7`
- `%` is modulus (remainder). Example: `x = 7 % 7`

You"ll notice that we"re defining a variable (`x`, in this example) each time we do math.
This is because nothing would happen if we just put `7+7` in our code; we wouldn"t be storing it anywhere.
You'll notice that we're defining a variable (`x`, in this example) each time we do math.
This is because nothing would happen if we just put `7+7` in our code; we wouldn't be storing it anywhere.

## What data types can I do math with?
The obvious choices for doing math are floats and integers, as they"re both represented as numbers we normally use in math.
The obvious choices for doing math are floats and integers, as they're both represented as numbers we normally use in math.
However, you can add (and sometimes multiply) other data types as well.
For instance, one way to join two strings together is by adding them. See this example:
```python
```Python
x = "first part "
y = "second part"
print(x + y)
Expand All @@ -32,7 +32,7 @@ For example, `x = "string" * 5` would result in `x` being `"stringstringstringst

## Can I turn a string into a number?
Yes! The builtin `int()` will turn your string into a number if possible.
`x = int("10")` would result in `10`, but `x = int("string")` would result in an error.
`x = int("10")` would result in `10`, but `x = int("string")` would result in an error because `string` is not a number.
You also cannot use the words of numbers. `x = int("ten")` will result in an error.
You can also convert strings to floats with the `float()` builtin.
`x = float("7.5")` would result in x being `7.5`. The last builtin we'll cover in this lesson is `str()`.
Expand All @@ -45,5 +45,8 @@ and the other will be a stringified float.
(Stringified just means converted to a string. `"7"` would be a stringified integer, because it's an integer as a string.)
First print out the two variables added together,
and then convert the first to an integer and the second to a float and print their sum again.
Keep in mind that `int(x)` will not turn `x` into an integer, you will have to redefine x like `x = int(x)`.
This will show the difference between adding two strings and two numbers -
when you add strings, their values are combined (`"5"` + `"5"` would be `"55"`, not `"10"`), but when you add
integers or floats, their values are added (`5` + `5` would be `10`).
Keep in mind that `int(x)` will not turn `x` into an integer; you will have to redefine `x` like `x = int(x)`.
Good luck, and click `Next` when you've gotten the proper results.
4 changes: 2 additions & 2 deletions resources/code.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"",
"",
"",
"# Here, display your variable's output with print().",
"# Here, display your variable's contents with print().",
"",
""
],
Expand All @@ -56,7 +56,7 @@
"",
"",
"",
"# Down here, display out your variable with print.",
"# Down here, display your variable with print.",
"",
"",
""
Expand Down
18 changes: 9 additions & 9 deletions static/lessons.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,15 +398,6 @@ function changeLesson(direction, platform) {
return
}
nextLesson = lessons_to_nums[variables['lesson']]+1
let answers
if (!localStorage.getItem('answers')) {
answers = {}
}
else {
answers = JSON.parse(localStorage.getItem('answers'))
}
answers[variables['lesson']] = variables['codeAreas'][platform]['input'].getValue()
localStorage.setItem('answers', JSON.stringify(answers))
}
else if (direction === 'back') {
if (document.getElementById(`back_${platform}`).classList.contains("invalid")) {
Expand All @@ -417,6 +408,15 @@ function changeLesson(direction, platform) {
if (nextLesson > lessons_to_nums[variables['last_lesson']]) {
localStorage.setItem("last_lesson", nums_to_lessons[nextLesson])
}
let answers
if (!localStorage.getItem('answers')) {
answers = {}
}
else {
answers = JSON.parse(localStorage.getItem('answers'))
}
answers[variables['lesson']] = variables['codeAreas'][platform]['input'].getValue()
localStorage.setItem('answers', JSON.stringify(answers))
localStorage.setItem("lesson", nums_to_lessons[nextLesson])
location.reload()
}
Expand Down

0 comments on commit 744f2e2

Please sign in to comment.