You know the code is part of the if/while/for loop if the code is ________.
Indented
len()
Which of the following does not have a Boolean expression: for, while, if
for
What is # used for in python?
to write comments
What is the syntax to create a list?
[] or list()
Add programmer to this list....
careers = ["doctor", "teacher", "accountant"]
careers.append("programmer")
What statement allows you to break out of a whole loop early?
break
Can you convert "dog" to an integer?
No
What is a python data type that represents numbers with decimal points?
float
How would you convert a variable, n, to a floating point number?
float(n)
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
What does this mean?
import re
Import the regular expressions library
Give an example of a boolean operator
!=, ==, >=, <=, <, >
What is the correct syntax for defining a function? (hint (): )
def functionName(inputVar):
.......return ()
a = “Santa Cruz, CA”
if a.count(“a”) == 3:
b = True
else:
b = False
print(“b is: “, b)
What does this print out?
False
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
Find the error in the code:
name = "Bob"
age = "9"
print("Hi! My name is ", name, ". I am ", age , " years old!")
No error! :D
What function do we use to interact with the user in the console?
input()
for i in range (100):
print (i)
would print the numbers from ___ to ____ inclusive.
0 to 99
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.