Accounting Expo
Shortcuts
F9 runs a current line (where the blinking cursor bar is) or selected lines.
Home/End moves the blinking cursor bar to the beginning/end of the line.
PgUp/PgDn moves the blinking cursor bar to the top/bottom line of the script on the screen.
Shortcuts
Mac
Windows
More Shortcuts
Code and comment style
# mark is Spyder's comment character.# character has many names: hash, sharp, pound, or octothorpe.# indicates that the rest of the line is to be ignored.# %% defines a coding block in Spyder.Let's look at the following Python’s simplest built-in data types in detail:
Booleans (which have the value True or False)
Integers (whole numbers such as 10 and 28)
Floats (numbers with decimal points such as 3.141592, or sometimes exponents like 1.0e8, which means one times ten to the eighth power, or 100000000.0)
Integer Operations
Python can be a simple calculator.
Here is a table of the math operators:

12 + 812 - 813 * 1.22 + 3 * 42 ** 32 / 02 // 0
Integers and Variables
=.a = 72a -= 2 # This is like a = a - 2
b = 62b += 2 # This is like b = b + 2
c = 72c *= 2 # This is like c = c * 2
d = 62d /= 2 # This is like d = d / 2
Type Conversions
To change other Python data types to an integer, use the int() function.
int() keeps the whole number and discard any fractional part.True and False are converted to integer values 1 and 0.
int(True)int(False)
bool(1)bool(0)
int(72.3)int(1.0e4)
bool(1.0)bool(0.0)
Floats
float() function.float(True)float(False)
float(88)float('89')
Class Exercises
Multiply the number of seconds in a minute (60) by the number of minutes in an hour (also 60) using Python.
Assign the result from the previous task (seconds in an hour) to a variable called seconds_per_hour.
How many seconds are in a day? Use your seconds_per_hour variable.
Calculate seconds per day again, but this time save the result in a variable called seconds_per_day
Divide seconds_per_day by seconds_per_hour. Use floating-point (/) division.
ifif Compare with if, elif, and else
Now, we finally take our first step into the code structures that weave data into programs.
The following Python program checks the value of the boolean variable disaster and prints an appropriate comment:
disaster = Trueif disaster: print("Woe!")else: print("Whee!")if Compare with if, elif, and else
if and else lines are Python statements that check whether a condition is a boolean True value, or can be evaluated as True.disaster = Trueif disaster: print("Woe!")else: print("Whee!")if Compare with if, elif, and else
Python expects you to be consistent with code within a section—the lines need to be indented the same amount, lined up on the left.
disaster = Trueif disaster: print("Woe!")else: print("Whee!")if Compare with if, elif, and else
disaster = Trueif disaster: print("Woe!")else: print("Whee!")
True to the variable named disaster.if and else, executing different code depending on the value of disaster.print() function to print some text.if Compare with if, elif, and else
furry = Truelarge = Trueif furry: if large: print("It's a yeti.") else: print("It's a cat!")else: if large: print("It's a whale!") else: print("It's a human. Or a hairless cat.")if Compare with if, elif, and else
if and else sections are paired.furry = Truelarge = Trueif furry: if large: print("It's a yeti.") else: print("It's a cat!")else: if large: print("It's a whale!") else: print("It's a human. Or a hairless cat.")if Compare with if, elif, and else
If there are more than two possibilities to test, use if for the first, elif (meaning else if) for the middle ones, and else for the last:
color = "mauve"if color == "red": print("It's a rasberry")elif color == "green": print("It's a green chili")elif color == "bee purple": print("I don't know what it is, but only bees can see it")else: print("I've never heard of the color", color)ifComparison Operators

ifComparison Operators
# Assign x to 7x = 7x == 5 # Test equalityx == 75 < xx < 10ifComparison Operators
Logical operators have lower precedence than the chunks of code that they’re comparing.
5 < x and x < 10
(5 < x) and (x < 10)ifComparison Operators
5 < x or x < 105 < x and x > 105 < x and not x > 10
and-ing multiple comparisons with one variable, Python lets you do this:5 < x < 10 # It’s the same as 5 < x and x < 10if What Is True?
True and False?False value doesn’t necessarily need to explicitly be a boolean False. False:

True.if What Is True?
False conditions:some_list = []if some_list: print("There's something in here")else: print("Hey, it's empty!")if Do Multiple Comparisons with in
if statement:letter = 'o'if letter == 'a' or letter == 'e' or letter == 'i' \ or letter == 'o' or letter == 'u': print(letter, 'is a vowel')else: print(letter, 'is not a vowel')if Do Multiple Comparisons with in
in, instead.vowels = 'aeiou'letter = 'o'letter in vowelsif letter in vowels: print(letter, 'is a vowel')if Do Multiple Comparisons with in
in with some data types:letter = 'o'vowel_set = {'a', 'e', 'i', 'o', 'u'}letter in vowel_setvowel_list = ['a', 'e', 'i', 'o', 'u']letter in vowel_listvowel_tuple = ('a', 'e', 'i', 'o', 'u')letter in vowel_tuplevowel_dict = {'a': 'apple', 'e': 'elephant', 'i': 'impala', 'o': 'ocelot', 'u': 'unicorn'}letter in vowel_dictin looks at the keys (the left-hand side of the :) instead of their values.vowel_string = "aeiou"letter in vowel_stringifWalrus Operator

tweet_limit = 280tweet_string = "Blah" * 50diff = tweet_limit - len(tweet_string)if diff >= 0: print("A fitting tweet")else: print("Went over by", abs(diff))tweet_limit = 280tweet_string = "Blah" * 50if ( diff := tweet_limit - len(tweet_string) ) >= 0: print("A fitting tweet")else: print("Went over by", abs(diff))ifClass Exercises
Choose a number between 1 and 10 and assign it to the variable secret. Then, select another number between 1 and 10 and assign it to the variable guess. Next, write the conditional tests (if, else, and elif) to print the string 'too low' if guess is less than secret, 'too high' if greater than secret, and 'just right' if equal to secret.
Assign True or False to the variables small and green. Write some if/else statements to print which of these matches those choices: cherry, pea, watermelon, pumpkin.
Accounting Expo
Keyboard shortcuts
| ↑, ←, Pg Up, k | Go to previous slide |
| ↓, →, Pg Dn, Space, j | Go to next slide |
| Home | Go to first slide |
| End | Go to last slide |
| Number + Return | Go to specific slide |
| b / m / f | Toggle blackout / mirrored / fullscreen mode |
| c | Clone slideshow |
| p | Toggle presenter mode |
| t | Restart the presentation timer |
| ?, h | Toggle this help |
| o | Tile View: Overview of Slides |
| Esc | Back to slideshow |
Accounting Expo
Shortcuts
F9 runs a current line (where the blinking cursor bar is) or selected lines.
Home/End moves the blinking cursor bar to the beginning/end of the line.
PgUp/PgDn moves the blinking cursor bar to the top/bottom line of the script on the screen.
Shortcuts
Mac
Windows
More Shortcuts
Code and comment style
# mark is Spyder's comment character.# character has many names: hash, sharp, pound, or octothorpe.# indicates that the rest of the line is to be ignored.# %% defines a coding block in Spyder.Let's look at the following Python’s simplest built-in data types in detail:
Booleans (which have the value True or False)
Integers (whole numbers such as 10 and 28)
Floats (numbers with decimal points such as 3.141592, or sometimes exponents like 1.0e8, which means one times ten to the eighth power, or 100000000.0)
Integer Operations
Python can be a simple calculator.
Here is a table of the math operators:

12 + 812 - 813 * 1.22 + 3 * 42 ** 32 / 02 // 0
Integers and Variables
=.a = 72a -= 2 # This is like a = a - 2
b = 62b += 2 # This is like b = b + 2
c = 72c *= 2 # This is like c = c * 2
d = 62d /= 2 # This is like d = d / 2
Type Conversions
To change other Python data types to an integer, use the int() function.
int() keeps the whole number and discard any fractional part.True and False are converted to integer values 1 and 0.
int(True)int(False)
bool(1)bool(0)
int(72.3)int(1.0e4)
bool(1.0)bool(0.0)
Floats
float() function.float(True)float(False)
float(88)float('89')
Class Exercises
Multiply the number of seconds in a minute (60) by the number of minutes in an hour (also 60) using Python.
Assign the result from the previous task (seconds in an hour) to a variable called seconds_per_hour.
How many seconds are in a day? Use your seconds_per_hour variable.
Calculate seconds per day again, but this time save the result in a variable called seconds_per_day
Divide seconds_per_day by seconds_per_hour. Use floating-point (/) division.
ifif Compare with if, elif, and else
Now, we finally take our first step into the code structures that weave data into programs.
The following Python program checks the value of the boolean variable disaster and prints an appropriate comment:
disaster = Trueif disaster: print("Woe!")else: print("Whee!")if Compare with if, elif, and else
if and else lines are Python statements that check whether a condition is a boolean True value, or can be evaluated as True.disaster = Trueif disaster: print("Woe!")else: print("Whee!")if Compare with if, elif, and else
Python expects you to be consistent with code within a section—the lines need to be indented the same amount, lined up on the left.
disaster = Trueif disaster: print("Woe!")else: print("Whee!")if Compare with if, elif, and else
disaster = Trueif disaster: print("Woe!")else: print("Whee!")
True to the variable named disaster.if and else, executing different code depending on the value of disaster.print() function to print some text.if Compare with if, elif, and else
furry = Truelarge = Trueif furry: if large: print("It's a yeti.") else: print("It's a cat!")else: if large: print("It's a whale!") else: print("It's a human. Or a hairless cat.")if Compare with if, elif, and else
if and else sections are paired.furry = Truelarge = Trueif furry: if large: print("It's a yeti.") else: print("It's a cat!")else: if large: print("It's a whale!") else: print("It's a human. Or a hairless cat.")if Compare with if, elif, and else
If there are more than two possibilities to test, use if for the first, elif (meaning else if) for the middle ones, and else for the last:
color = "mauve"if color == "red": print("It's a rasberry")elif color == "green": print("It's a green chili")elif color == "bee purple": print("I don't know what it is, but only bees can see it")else: print("I've never heard of the color", color)ifComparison Operators

ifComparison Operators
# Assign x to 7x = 7x == 5 # Test equalityx == 75 < xx < 10ifComparison Operators
Logical operators have lower precedence than the chunks of code that they’re comparing.
5 < x and x < 10
(5 < x) and (x < 10)ifComparison Operators
5 < x or x < 105 < x and x > 105 < x and not x > 10
and-ing multiple comparisons with one variable, Python lets you do this:5 < x < 10 # It’s the same as 5 < x and x < 10if What Is True?
True and False?False value doesn’t necessarily need to explicitly be a boolean False. False:

True.if What Is True?
False conditions:some_list = []if some_list: print("There's something in here")else: print("Hey, it's empty!")if Do Multiple Comparisons with in
if statement:letter = 'o'if letter == 'a' or letter == 'e' or letter == 'i' \ or letter == 'o' or letter == 'u': print(letter, 'is a vowel')else: print(letter, 'is not a vowel')if Do Multiple Comparisons with in
in, instead.vowels = 'aeiou'letter = 'o'letter in vowelsif letter in vowels: print(letter, 'is a vowel')if Do Multiple Comparisons with in
in with some data types:letter = 'o'vowel_set = {'a', 'e', 'i', 'o', 'u'}letter in vowel_setvowel_list = ['a', 'e', 'i', 'o', 'u']letter in vowel_listvowel_tuple = ('a', 'e', 'i', 'o', 'u')letter in vowel_tuplevowel_dict = {'a': 'apple', 'e': 'elephant', 'i': 'impala', 'o': 'ocelot', 'u': 'unicorn'}letter in vowel_dictin looks at the keys (the left-hand side of the :) instead of their values.vowel_string = "aeiou"letter in vowel_stringifWalrus Operator

tweet_limit = 280tweet_string = "Blah" * 50diff = tweet_limit - len(tweet_string)if diff >= 0: print("A fitting tweet")else: print("Went over by", abs(diff))tweet_limit = 280tweet_string = "Blah" * 50if ( diff := tweet_limit - len(tweet_string) ) >= 0: print("A fitting tweet")else: print("Went over by", abs(diff))ifClass Exercises
Choose a number between 1 and 10 and assign it to the variable secret. Then, select another number between 1 and 10 and assign it to the variable guess. Next, write the conditional tests (if, else, and elif) to print the string 'too low' if guess is less than secret, 'too high' if greater than secret, and 'just right' if equal to secret.
Assign True or False to the variables small and green. Write some if/else statements to print which of these matches those choices: cherry, pea, watermelon, pumpkin.