SYNTAX
FUNCTIONS
LOOPS & If Statements

MISC
100

You know the code is part of the if/while/for loop if the code is ________.

Indented

100
What function returns the length of a variable?

len()

100

Which of the following does not have a Boolean expression: for, while, if

for 


100

What is # used for in python?

to write comments


200

What is the syntax to create a list?

[] or list()

200

Add programmer to this list....

careers = ["doctor", "teacher", "accountant"] 

careers.append("programmer")

200

What statement allows you to break out of a whole loop early?

break

200

Can you convert "dog" to an integer?

No 

300

What is a python data type that represents numbers with decimal points?

float

300

How would you convert a variable, n, to a floating point number?

float(n)

300

TRIPLE POINTS (600!!): The squirrels in Palo Alto spend most of the day playing. In particular, they play if the temperature is between 60 and 90 (inclusive). Unless it is summer, then the upper limit is 100 instead of 90. Write a function that takes an int temperature and a boolean is_summer, return True if the squirrels play and False otherwise.

def doSquirrelsPlay(temp, is_summer):

    if (is_summer):

        if (60<= temp <= 100):

            return True

        else:

            return False

    elif (60<= temp <=90) :

        return True

    else:

        return False

300

What does this mean?


import re

Import the regular expressions library

400

Give an example of a boolean operator

!=, ==, >=, <=, <, > 

400

What is the correct syntax for defining a function? (hint (): )

def functionName(inputVar):

     .......return ()


400

a = “Santa Cruz, CA” 

if a.count(“a”) == 3:

    b = True

else:

    b = False 

print(“b is: “, b)


What does this print out?

False

400

Interpret this common error:

Traceback (most recent call last):  

File "/home/stanley/code_samples/main.py", line 1, in <module>    print("hello" / 3) 

TypeError: unsupported operand type(s) for /: 'str' and 'int'

There is a mismatch between types -- you can't divide a string by an integer


500

Find the error in the code:

name = "Bob"

age = "9"

print("Hi! My name is ", name, ". I am ",  age , " years old!")

No error! :D 

500

 What function do we use to interact with the user in the console?

input()

500

for i in range (100):

       print (i)


would print the numbers from ___ to ____ inclusive. 

0 to 99

500

Why will a user input of 7 get you an error?

usernum = input("Enter a number: ")

threex = usernum * 3

print(usernum, " x 3 = ", threex)

User inputs are always strings! You need to convert this to an int first.

M
e
n
u