<jupyter_start><jupyter_text>Integers Note: You can practice these exercises in Jupyter Notebook, or by creating a practice.py script in your editor then running that script in terminal. Both skills are important, so switching back and forth is a good idea. The instructor will demonstrate both ways to do this, but for lectures, will demonstrate mostly in Jupyter Notebook.<jupyter_code>7
12
0<jupyter_output><empty_output><jupyter_text>Floats<jupyter_code>4.2
1.234
34.0<jupyter_output><empty_output><jupyter_text>Complex<jupyter_code>complex(3,2)
complex(4,7)
complex(2,3)<jupyter_output><empty_output><jupyter_text>Numeric Operations<jupyter_code># Addition
7 + 8
# Subtraction
7 - 8
# Multiplication
7 * 8
# Division
7 / 8
# Floor division - the result rounded down to the nearest integer. 
7 // 8
# Exponent
7 ** 8
# Modular division - the result is the remainder from division
71 % 7<jupyter_output><empty_output><jupyter_text>Manual Casting<jupyter_code>int(7.0)
float(7)
float(7//8)
# More on non-numeric types later
str(7)<jupyter_output><empty_output><jupyter_text>Defining Variables<jupyter_code>x = 2
x
x + 3
# Good variable names are important
# Use snake_case
degrees_f = 45
# Bad variable names get confusing
d_c = 7.22
# Some variables are used frequently, so simple is okay
# i is used to keep track of indexing, so most readers of your code will understand what you mean
i = 0
# Variables can change
x = 2
x = x + 7
x
# Syntactic sugar 
x += 1
x
y = 12
y -= 2
y
a = 1
a *= 10
a<jupyter_output><empty_output><jupyter_text>Finding Variable Types<jupyter_code>x = 45
type(x)
type(7.2)
x += 0.2
type(x)<jupyter_output><empty_output><jupyter_text>Comments<jupyter_code># It is very important that your code is readable to others and to your
# future self. Comment as often as you think is necessary to spell out
# what some specific piece of code is supposed to do. 

# Define a variable called x and set it equal to 1
x = 1

# Increase the x variable by 2 
x += 2<jupyter_output><empty_output><jupyter_text>Logic - If, Elif, Else<jupyter_code># Set x equal to some number
x = 4
# if x is greater than or equal to 2, increase x by 1
if x >= 2:
    x += 1
x
# if x is not equal to 7, decrease x by 1
if x != 7:
    x -= 1
x
# if x is less than or equal to 10, increase x by 2
# elif x is less than or equal to 5, increase x by 1
# else, increase x by 0
if x <= 10:
    x += 2
elif x <=5:
    x += 1
else:
    x += 0
x
# Just a follow up not on the bool type
type(True)
type(False)
1 == 2
4 == 4.0
1 < 2
x = 4
y = 2
x <= y
# Here's how to print something in Python directly
z = 45
if z < 100:
    print(z)
else:
    print(0)
# You don't need to know the value of x, you can use if statements to
# execute code based on a condition which x may or may not meet
if x > 5:
    x += 10
print(x)<jupyter_output>4<jupyter_text>Input from User<jupyter_code>x = input('Please enter a number: ')
print(x)
# Notice that the input will assume that the input is a string 
# (more on strings later)
type(x)
# If you want the input to be a number:
x = int(input('Please enter a number: '))
type(x)
# Now, a user can enter a number and you don't have to know what that
# number is to execute some conditions

if x <= 50:
    x -= 20
elif x > 50:
    x += 2
else:
    x -= 1
print(x)
x = int(input('Please enter a number: '))
if x > 5:
    print('You entered a number bigger than 5.')
elif x > 0:
    print('You entered a positive number.')
elif x < 0:
    print('You entered a negative number.')
else:
    print('You entered the number 0.')<jupyter_output>Please enter a number: 45
You entered a number bigger than 5.<jupyter_text>And, Or, Not<jupyter_code>x = 30
# What if you want multiple if statements together?
# If x is both greater than 50 and less than 60?
x = int(input('Please enter a number: '))
if x > 50 and x < 60:
    print(x)
else:
    print('No thanks.')
# Here (x + 1) will print if x is either equal to 5 or 45. 
if x == 5 or x == 45:
    print(x+1)
# Here, x will print if it is NOT between 5 and 10
if not (x > 5 and x < 10):
    print(x)<jupyter_output>45<jupyter_text>While Loops<jupyter_code># Not so hard of a problem
sum_1_8 = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8
print(sum_1_8)
# What if you had to sum to 100? Clearly the above code is 'brittle'

# initialize two variables, one to track total sum
# and one to track where we are in the calculation (the steps to take)

total = 0
i = 1
end = 1000

# loop over both variables: while i is less than the end we want to reach
# add that i to the total sum
# increment i by 1 to continue the loop
# when the loop reaches the end, it'll stop and total will be printed
# now all I have to do to add numbers to 1000 is th change the variable
# called 'end'

while i <= end:
    total += i
    i += 1
print(total)
total = 0
i = 1
end = int(input('Please enter a number: '))

if end > 0:
    while i <= end:
        total += i
        i += 1
print(total)<jupyter_output>Please enter a number: 8
36<jupyter_text>Nested Loops<jupyter_code># Clock example: 
# Day == 24 hours numbered 0-23
# Hour == 60 minutes
# Minute == 60 seconds
# Seconds increment fastest, followed by minutes, then hours, etc

hours = 0
while hours < 24:
    minutes = 0
    while minutes < 60:
        seconds = 0
        while seconds < 60:
            #print(hours, minutes, seconds)
            seconds += 1
        minutes += 1
    hours += 1
    
# Walk through this in class<jupyter_output><empty_output><jupyter_text>Continue, Pass, Break<jupyter_code># Establish two variables (you can do this on the same line)
total, x = 0, 1

# at each iteration, if the current value is equal to 5
# increase x by 1, but if isn't, add x to the total and keep going
# The continue allows you to skip the remainder of the block and jumps
# to the next iteration of the loop without adding 5

while x <= 8:
    if x == 5:
        x += 1
        continue
    total += x
    x += 1
    print(total, x)
print(total)
# While continue allowed you to skip the rest of the loop's code
# and jump directly back into the next iteration of the loop
# break will have you exit the loop entirely 

total, x = 0, 1

while x <= 8:
    if total > 25:
        total = 25
        print('The sum exceeded the max value of 25.')
        break
    total += x
    x += 1
    print(total)
print(total)

# Look at the position of the print statements
# adding print statements in different places can help you visualize
# different parts of your code. If you're unsure of what is happening
# in your code, print it out.
# All Pass does it tell Python to do nothing.
# Helps you code outlines of what you want to accomplish.

if x < 0:
    pass
elif x > 0:
    pass
else:
    print('x is the value of 0.')<jupyter_output><empty_output><jupyter_text>FizzBuzz Class Challenge<jupyter_code>import pdb
end = 50
x = 0

while x <= end:
    if (x % 3 == 0) and (x % 5 == 0):
        print(x, 'Fizz Buzz')
    elif x % 3 == 0:
        print(x, 'Fizz')
    elif x % 5 == 0:
        print(x, 'Buzz')
    else:
        print(x)
    x += 1
    
import pdb
if x < 0:
    pdb.set_trace()
    print(x)
elif x > 0:
    pass
else:
    print('x is the value of 0.')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09172010036241984, 'fraction_numerical': 0.0335935321996097, 'mean_word_length': 3.2810262529832936, 'pattern_counts': {'":': 0, '<': 76, '<?xml version=': 0, '>': 68, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '15', 'dir': 'jupyter-structured-clean-dedup', 'id': '76627', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 2647, 'n_tokens_neox': 2410, 'n_words': 1086, 'path': 'python_lecture_one.ipynb', 'repo_name': 'GalvanizeOpenSource/bdr-platte-intro-to-ds-oct-2018', 'size': '7174'}