# Integer data
type( 17 )

# Floating-point data
type( 17.0 )

# A number inside a string
type( '17' )

"""
Explanation: Chapter 2: Variables, expressions, and statements

Contents
- Values and types
- Variables
- Variable names and keywords
- Statements
- Operators and operands
- Expressions
- Order of operations
- String operations
- Comments
- Exercises

This notebook is based on "Think Python, 2Ed" by Allen B. Downey <br>
https://greenteapress.com/wp/think-python-2e/

Values and types

A value is a basic piece of data
Values belong to different types (or, more commonly, datatypes)
Python will tell you what type a value is using the type function
Integer values are whole numbers
Numbers with decimal types are referred to as float-point values
End of explanation
"""


count = 55
size = 42.0

"""
Explanation: Variables

A variable is a name, or label for a value
It has no inherent meaning
An assignment statement gives a variable a value
In Python, it even creates the variable if it hasn't been created before
End of explanation
"""


print( count )

"""
Explanation: The print function displays the value of a variable
End of explanation
"""


type( count )

"""
Explanation: The type of a variable is the type of its value
End of explanation
"""


# Operator: + (addition)
# Operands: 3 and 4
3 + 4

# Operator: - (subtraction)
# Operands: 3 and 4
3 - 4

# Operator: *tiplication (mul)
# Operands: 3 and 4
3 * 4

# Operator: / (division)
# Operands: 3 and 4
3 / 4

"""
Explanation: Variable names and keywords

Variables names need to be meaningful
Don't use x, y, and z as names unless they have real meaning in the problem (like 3-d points)
Variable names can be arbitrarily long and can contain:
letters
numbers
underscores
They have to begin with a letter
You can use uppercase letters, but start variables with a lowercase letter
Python is case sensitive so max and Max are different variables
An illegal variable name is a syntax error
Python has 30 keywords which are words that mean something specific in the language

Statements

A statement is a unit of code that the Python interpreter can execute
Usually a statement is a single line of code, but
It can be longer depending on the type of statement
A script (or program) usually contains a sequence of statements

Operators and operands

Operators are special symbols that represent computations like addition and multiplication
The value(s) to which the operator is applied is called an operand
End of explanation
"""


10 / 3

10 // 3

"""
Explanation: There is a special division operator // called floor division
It throws away the remainder
End of explanation
"""


5 * 2

5 * 2.0

5.0 * 2

5.0 * 2.0

"""
Explanation: If either operand is a float, the result is a float
End of explanation
"""


1.0 / ( 2 * 3.14159 )

"""
Explanation: Expressions

An expression is a combination of values, variables and operators
A value or a variable is itself an expression
The interpreter evaluates expressions and uses the result for other expressions or simply displays it (if it is executed in the console)
A statement is comprised of one or more expressions

Order of operations

The order in which operators are evaluated in an expression depends on the rules of precedence
Python follows the standard mathematical convention
You may know it as PEMDAS
Parenthesis
Exponent
Multiplication
Division
Addition
Subtraction
End of explanation
"""


# Can't divide a string by an integer
# Uncomment to demonstrate
# '13' / 42

"""
Explanation: String operations

In general, you can't use mathematical operators with string values or variables
Even if the strings look like numbers
End of explanation
"""


'fizz' + 'buzz'

"""
Explanation: One exception is the + operator
It performs concatenation with strings
This means that it joins strings together
End of explanation
"""


'la' * 3

"""
Explanation: Another exception is the * operator
It repeats a string
End of explanation
"""


# Poor example
# Calculate it
y = 2
x = 2 * 3.14 * y

# Good example
# Calculate circumference of a circle
pi = 3.14
radius = 2
circumference = 2 * pi * radius

"""
Explanation: Comments

Comments are a way for you to add notes to your program
They improve understanding of your code by describing the why of the code
Code already provides the how, so don't have your comments repeat that
This assumes that your code is understandable an you have chosen appropriate variable names
End of explanation
"""


