Print()
What error would be the result of the above code?
Name Error
What is the difference between , comma and + plus when combining a string.
Comma puts a space in between two items and the plus does not.
What type is the following variable after the code is run?
number1 = num2/num3
It is a float. Division always results in a float
How can you add a tab (Multiple spaces between other characters) in a text string?
Use escape character \t
What is a logic Error?
1 When you enter the wrong punctuation
2 When at variable does not exist
3 Your code does not work as intended
3 Your code does not work as intended
Which variable name is illegal in Python?
A more_Days
B 2moreDays
It is B
B 2moreDays - No numbers at the beginning of variables.
What is the output of the Python below program?
def sayHello():
print('Hello World!')
sayHello()
sayHello()
Be Specific!
Hello World! - Twice
Which operator can be used to check if two values are not equal?
A !
B ==
C !=
C !=
The variable in a loop that determines how many times a loop iterates and is usually incremented or decremented by 1 is called a __
counter
True or False - pass can be used when you don't have an idea what you want to put in part of your code but you still want it to work
True
What does type(True) return?
bool - or Boolean
True and False are Boolean variable types
Which of the following is true about the use of functions in Python?
A Functions don’t provide better modularity for your application
B You can only sometimes create your own functions
C Functions are reusable pieces of programs
C Functions are reusable pieces of programs
calculation = 5 + 20 / 5 + 3 * 2 - 1
print(calculation)
What is the best estimate for the output of the above code?
Be Specific!
14.0
The programmer wants the loop to display a sum of the first 10 integers. What kind of error occurs in the code and how can it be fixed?
numSum = 0
count = 1
while count <= 10:
numSum += count
count -= 1
print(numSum)
Logic error because the counter is decrementing instead of incrementing and causing an infinite loop.
count -= 1 Change to -> count += 1
In the code snippet below, what are the argument(s) of the function call?
def makeSerialNum(partNum):
serialNum = "ABC" + partNum + " - y"
return serialNum
part = input("Enter part number: ")
sNum = makeSerialNum(part)
print("For part " + part + " the serial number is " + sNum)
1 part
2 partNum
3 part and partNum
1 part
Which is a valid comment in Python
A '# One of these is right
B '''' One of these is right ''''
C ''' One of these is right '''
3 (''') Apostrophes in a multiple line comment
C ''' One of these is right
What is the output of below program?
def cube(x):
return x * x * x
x = cube(3)
print(x)
27
3 * 3 * 3 =
9 * 3 =27
x is the parameter and 3 is the argument placed into the function
day = "friday"
if day.capitalize() == "Friday":
print("End the week!")
else:
pass
What is the output from running the above code?
End the week!
What will be displayed by the following code?
count = 8
while count < 8:
print("Hello")
count -=1
No Output
Because you start the counter at 8 the loop never starts
Which of the following statements in Python will allow a loop to exit early?
1 exit
2 continue
3 pass
4 break
4 break
answer = input("enter your answer: ")
print(10 + answer)
If user input is 50, what is the output of the above code?
Be specific!
It is a TypeError.
Because you cannot add 10 to a string. Input functions always provide a String Output
What is the output of the following code if the user enters 5:
def findSquare(num = 6):
return num * num
num = input("Enter a number: ")
mySquare = findSquare()
print(num, "squared is", mySquare)
5 squared is 36
This is tricky but function was defined with num = 6. The input statement never went into findSquare() function.
hotPlate = 65 < 60
if hotPlate:
print("Be careful, hot plate!")
else:
print("The plate is ready.")
What is the output from running the above code?
The plate is ready.
While loops can execute this possible number of times.
Hint: There are 3 specific answers
0, finite or infinite
sizeNum = "8 9 10"
size = input("Enter your shoe size: ")
if size.isdigit() == False:
print("Invalid: size should only use digits")
elif int(size) < 8:
print("size is too low")
elif size in sizeNum:
print("size is recorded")
else:
print("size is too high")
A. Invalid: size should only use digits
B size is too high
C size is too low
D size is recorded
D size is recorded