# The interpreter can be used as a calculator, and can also echo or concatenate strings.

3 + 3

3 * 3

3 ** 3

3 / 2 # classic division - output is a floating point number

# Use quotes around strings

'dogs'

# + operator can be used to concatenate strings

'dogs' + "cats"

print('Hello World!')

"""
Explanation: Examples: Variables and Data Types
The Interpreter
End of explanation
"""


a = 5
b = 10
a + b

"""
Explanation: Try It Yourself
Go to the section 4.4. Numeric Types in the Python 3 documentation at https://docs.python.org/3.4/library/stdtypes.html. The table in that section describes different operators - try some!
What is the difference betwee## Variables
Variables allow us to store values for later use. n the different division operators (/, //, and %)?
Variables
Variables allow us to store values for later use.
End of explanation
"""


b = 38764289.1097
a + b

"""
Explanation: Variables can be reassigned.
End of explanation
"""


a = 5
b = 10
while b > a:
    print("b="+str(b))
    b = b-1

"""
Explanation: The ability to reassign variable values becomes important when iterating through groups of objects for batch processing or other purposes. In the example below, the value of b is dynamically updated every time the while loop is executed:
End of explanation
"""


a = 5
type(a)

"""
Explanation: Variable data types can be inferred, so Python does not require us to declare the data type of a variable on assignment.
End of explanation
"""


a = int(5)
type(a)

c = 'dogs'
print(type(c))

c = str('dogs')
print(type(c))

"""
Explanation: is equivalent to
End of explanation
"""


customer = 'Carol'
pizzas = 2
print(customer + ' ordered ' + pizzas + ' pizzas.')

"""
Explanation: There are cases when we may want to declare the data type, for example to assign a different data type from the default that will be inferred. Concatenating strings provides a good example.
End of explanation
"""


customer = 'Carol'
pizzas = str(2)
print(customer + ' ordered ' + pizzas + ' pizzas.')

customer = 'Carol'
pizzas = 2
print(customer + ' ordered ' + str(pizzas) + ' pizzas.')

"""
Explanation: Above, Python has inferred the type of the variable pizza to be an integer. Since strings can only be concatenated with other strings, our print statement generates an error. There are two ways we can resolve the error:

Declare the pizzas variable as type string (str) on assignment or
Re-cast the pizzas variable as a string within the print statement.
End of explanation
"""


# Separate list items with commas!

number_list = [1, 2, 3, 4, 5]
string_list = ['apples', 'oranges', 'pears', 'grapes', 'pineapples']
combined_list = [1, 2, 'oranges', 3.14, 'peaches', 'grapes', 99.19876]

# Nested lists - lists of lists - are allowed.

list_of_lists = [[1, 2, 3], ['oranges', 'grapes', 8], [['small list'], ['bigger', 'list', 55], ['url_1', 'url_2']]]

"""
Explanation: Given the following variable assignments:
x = 12
y = str(14)
z = donuts
Predict the output of the following:

y + z
x + y
x + int(y)
str(x) + y

Check your answers in the interpreter.
Variable Naming Rules
Variable names are case senstive and:

Can only consist of one "word" (no spaces).
Must begin with a letter or underscore character ('_').
Can only use letters, numbers, and the underscore character.

We further recommend using variable names that are meaningful within the context of the script and the research.
Lists
https://docs.python.org/3/library/stdtypes.html?highlight=lists#list
Lists are a type of collection in Python. Lists allow us to store sequences of items that are typically but not always similar. All of the following lists are legal in Python:
End of explanation
"""


# Create an empty list

empty_list = []

# As we did above, by using square brackets around a comma-separated sequence of items

new_list = [1, 2, 3]

# Using the type constructor

constructed_list = list('purple')

# Using a list comprehension

result_list = [i for i in range(1, 20)]

"""
Explanation: There are multiple ways to create a list:
End of explanation
"""


empty_list

new_list

result_list

constructed_list

"""
Explanation: We can inspect our lists:
End of explanation
"""


constructed_list_int = list(123)

constructed_list_str = list('123')
constructed_list_str

"""
Explanation: The above output for typed_list may seem odd. Referring to the documentation, we see that the argument to the type constructor is an iterable, which according to the documentation is "An object capable of returning its members one at a time." In our construtor statement above
```
Using the type constructor
constructed_list = list('purple')
```
the word 'purple' is the object - in this case a word - that when used to construct a list returns its members (individual letters) one at a time.
Compare the outputs below:
End of explanation
"""


ordered = [3, 2, 7, 1, 19, 0]
ordered

# There is a 'sort' method for sorting list items as needed:

ordered.sort()
ordered

"""
Explanation: Lists in Python are:

mutable - the list and list items can be changed
ordered - list items keep the same "place" in the list

Ordered here does not mean sorted. The list below is printed with the numbers in the order we added them to the list, not in numeric order:
End of explanation
"""


string_list = ['apples', 'oranges', 'pears', 'grapes', 'pineapples']

string_list[0]

# We can use positions to 'slice' or selection sections of a list:

string_list[3:]

string_list[:3]

string_list[1:4]

# If we don't know the position of a list item, we can use the 'index()' method to find out.
# Note that in the case of duplicate list items, this only returns the position of the first one:

string_list.index('pears')

string_list.append('oranges')

string_list

string_list.index('oranges')

"""
Explanation: Info on additional list methods is available at https://docs.python.org/3/library/stdtypes.html?highlight=lists#mutable-sequence-types
Because lists are ordered, it is possible to access list items by referencing their positions. Note that the position of the first item in a list is 0 (zero), not 1!
End of explanation
"""


