TECHSMART EXAM QUESTIONS AND 100%
CORRECT ANSWERS
If statement - ANSWER An if statement, or conditional, is a code structure that
makes a decision. It is composed of a line that asks a question, and then one or
more indented lines that run or are skipped based on the answer to that question.
What value is printed out by this code?
x = 100
if x > 0:
x -= 1
print(x) - ANSWER 99
What value is printed out by this code?
x=0
if x < 0:
x += 1
print(x) - ANSWER 0
Fix the error in this code that stops it from running.
user_day = input("Enter a date: ")
day = "September 21"
if day = user_day:
print ("Oh! How did you know the secret date?") - ANSWER user_day =
input("Enter a date: ")
day = "September 21"
if day == user_day:
print ("Oh! How did you know the secret date
Which of the following is true about the decision-making lines (clauses) in
conditionals?
They always contain a keyword and a colon
They always contain a condition
, They are always indented
They are always surrounded by blank lines - ANSWER They always contain a
keyword and a colon
Highlight the condition in the following code. Do not highlight any extra
characters.
my_var = 0
if my_var > 99:
print ("This number has at least 3 digits..") - ANSWER my_var = 0
if my_var > 99:
print ("This number has at least 3 digits..")
What symbol is used in Python to raise one number to the power of another
number? (exponentiation operator)
//
**
%%
++ - ANSWER **
What is the chance that the secret item will be "bell"? Give your answer as a
fraction.
import random
secret = random.randint(1, 6)
if secret == 1:
secret_item = "pin"
elif secret == 2:
secret_item == "toy"
elif secret == 3:
secret_item = "cookie"
else:
secret_item == "bell" - ANSWER 3/6
Replace the _ symbol in the following code with the operator that gets the
remainder after division (modulo).
CORRECT ANSWERS
If statement - ANSWER An if statement, or conditional, is a code structure that
makes a decision. It is composed of a line that asks a question, and then one or
more indented lines that run or are skipped based on the answer to that question.
What value is printed out by this code?
x = 100
if x > 0:
x -= 1
print(x) - ANSWER 99
What value is printed out by this code?
x=0
if x < 0:
x += 1
print(x) - ANSWER 0
Fix the error in this code that stops it from running.
user_day = input("Enter a date: ")
day = "September 21"
if day = user_day:
print ("Oh! How did you know the secret date?") - ANSWER user_day =
input("Enter a date: ")
day = "September 21"
if day == user_day:
print ("Oh! How did you know the secret date
Which of the following is true about the decision-making lines (clauses) in
conditionals?
They always contain a keyword and a colon
They always contain a condition
, They are always indented
They are always surrounded by blank lines - ANSWER They always contain a
keyword and a colon
Highlight the condition in the following code. Do not highlight any extra
characters.
my_var = 0
if my_var > 99:
print ("This number has at least 3 digits..") - ANSWER my_var = 0
if my_var > 99:
print ("This number has at least 3 digits..")
What symbol is used in Python to raise one number to the power of another
number? (exponentiation operator)
//
**
%%
++ - ANSWER **
What is the chance that the secret item will be "bell"? Give your answer as a
fraction.
import random
secret = random.randint(1, 6)
if secret == 1:
secret_item = "pin"
elif secret == 2:
secret_item == "toy"
elif secret == 3:
secret_item = "cookie"
else:
secret_item == "bell" - ANSWER 3/6
Replace the _ symbol in the following code with the operator that gets the
remainder after division (modulo).