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
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
What Brackets help you slice a string?
1 {}
2 ()
3 []
3 []
Square brackets
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
Hello World!
Which operator can be used to check if two values are not equal?
A !
B ==
C !=
C !=
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
The last character in a string can be accessed at index -1 or len(string) - 1.
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 + 15 / 5 + 3 * 2 - 1
print(calculation)
What is the best estimate for the output of the above code?
Be Specific!
13.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
Which choice will print the first half of the word "Consequences", given the following variable declaration?
word = "Consequences"
1 print(word[6:len(word)])
2 print(word[:int(len(word) / 2)])
3 print(word[1:7])
2 print(word[:int(len(word) / 2)])
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 the following code if the user enters 5:
def findSquare(num = 10):
return num * num
num = input("Enter a number: ")
mySquare = findSquare()
print(num, "squared is", mySquare)
5 squared is 100
This is tricky but function was defined with num = 10. The input statement never went into findSquare() 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!
How can you add a tab (Multiple spaces between other characters) in a text string?
Use escape character \t
Which choice will return –1, given the following variable assignment below?
word = "Python"
1 word.find("P")
2 word.find("y")
3 word.find("Z")
4 word.find("N".lower())
3 word.find("Z")
-1 means the value was not found
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 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
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
What is the output of the following code?
word = "innovation"
myWord = ""
for ltr in word[-1::-2]:
myWord += ltr
Be specific with your answer. What letters would print
print(myWord)
niaon
Start at the end (-1) and go backwards by 2