Update Codecademy docs.

This commit is contained in:
Josh Mudge 2018-12-15 14:35:53 -07:00
parent e5793ce5cd
commit fc64fd9ab1
1 changed files with 86 additions and 3 deletions

View File

@ -1,11 +1,94 @@
# Codecademy's Python 2 Course
https://www.codecademy.com/courses/learn-python/lessons/python-syntax/
It's gratis and accepts Python 3 syntax.
# Object-oriented # Object-oriented
"The main goal of an object oriented language is to make code reusable we do this through the use of classes and objects. If we want to design a new type of car, we can start with what they all have in common: wheels, seats, a frame. Now that weve determined what cars have in common, we can more easily implement any type of car we want by starting from that basic blueprint." "The main goal of an object oriented language is to make code reusable we do this through the use of classes and objects. If we want to design a new type of car, we can start with what they all have in common: wheels, seats, a frame. Now that weve determined what cars have in common, we can more easily implement any type of car we want by starting from that basic blueprint."
https://discuss.codecademy.com/t/what-does-it-mean-that-python-is-an-object-oriented-language/297314 https://discuss.codecademy.com/t/what-does-it-mean-that-python-is-an-object-oriented-language/297314
# Errors # Errors (ex5)
print("With mismatched quotes will cause a SyntaxError") "Mismatched quotes will cause a SyntaxError'
print("Without quotes will cause a NameError") "SyntaxError: EOL while scanning a string literal"
No quotes will cause a NameError (interprets strings as commands. )
# Math (ex6)
```
mirthful_addition = 12381 + 91817
amazing_subtraction = 981 - 312
trippy_multiplication = 38 * 902
happy_division = 540 / 45
sassy_combinations = 129 * 1345 + 120 / 6 - 12
```
## Find the remainder of a number using %
```
is_this_number_odd = 15 % 2
is_this_number_divisible_by_seven = 133 % 7
```
# Updating variables / operators.
```
sandwich_price += sales_tax
```
is the same as:
```
sandwich_price = sandwich_price + sales_tax
```
but is much shorter.
## Comments
Are indicated by # or """This is not for running"""
# Numbers
An integer is like `5`, a float is a number with a decimal point like `5.0`. They can also be in scientific notation like `2.3e7`
To make sure math like `7/2` = `3.5` is correct is by inputting it into Python like `7./2.` or `float(7)/2`
# Strings
Multi-line strings are marked by ```"""Mulit-
line
strings"""```
# Booleans (True/False)
True = int(1)
False = int(0)
# Fun Projects
Design a shop using Ex7 and Ex9 as a frame:
7:
```
money_in_wallet = 40
sandwich_price = 7.50
sales_tax = .08 * sandwich_price
sandwich_price += sales_tax
money_in_wallet -= sandwich_price
```
9:
```
cucumbers = 1
price_per_cucumber = 3.25
total_cost = cucumbers * price_per_cucumber
print(total_cost)
```