CSC105 Intro to Programming Flashcards
The following statement will evaluate to True:
5 > 6) OR (12 < 14
True
The following statement will evaluate to True:
5 > 6) AND (12 < 14
False
Which of the following operators is used in most languages to test if two operands do not have the exact same value?
!=
In a Python program, if the variable value1 is set to 2.0 and and variable value2 is set to 12, what is the output of the following command?
print(value1 * value2)
24.0
Which of the choices is equivalent to the following decision?
if x > 10 then
if y > 10 then output "X" endif endif
if x > 10 AND y > 10 then output “X” endif
Which of the following must always be false?
e > 10 AND e < 7
In the following pseudocode, what percentage raise will an employee in department 8 receive?
if department < 5 then
raise = SMALL_RAISE else if department < 14 then raise = MEDIUM_RAISE else if department < 9 then raise = BIG_RAISE
MEDIUM_RAISE
If sales = 100, rate = 0.10, and expenses = 50, which of the following expressions is true?
sales >50 AND expenses <=100
Which of the following is the correct “if” clause to determine whether y is in the range 10 through 50?
if y >= 10 and y <= 50
Given the following function definition, what would the statements display?
def magic(num): return num + 2 * 10
result = magic(5)
print(result)
25
What is the result of the following Boolean expression, if x equals 5, y equals 3, and z equals 8?
x < y or z > x
True
What is the result of the following Boolean expression, if x equals 5, y equals 3, and z equals 8?
not (x < y or z > x) and y < z
False
Design pseudocode for a module named timesTen. The module should accept an integer argument. When the module is called, it should display the product of its argument multiplied by 10.
After you write the module, call the module passing a 20 to it.
Your Answer: Module timesTen(integerValue)
Declare integerResult
Set integerResult = integerValue * 10
Display result
End Module
result = 200
COMMENT: Need to call your module with an argument of 20
Design pseudocode for a module named getNumber, which uses a reference parameter variable to accept an Integer argument. The module should prompt the user to enter a number and then store the input in the reference parameter variable.
After you write the module, call the module.
Your Answer: Module getNumber(Real Ref integerValue)
Display “Enter a number: “
Input number
End Module
Module main
Call getNumber
End Module
COMMENT: Need to include argument in your getNumber call
What will the following pseudocode program display?
Module main() Declare Integer x = 1 Declare Real y = 3.4 Display x, " ", y Call doSomething(x, y) Display x, " ", y End Module Module doSomething(Integer a, Real b) Set a = 0 Set b = 0 Display a, " ", b End Module
Your Answer:
Nothing; there is nothing within the quotation marks of the Displays
COMMENT: Actually, we are concatenating three things. The value in x, “ “ (which is a blank space), and the value in y. This will result in 1 3.4 for the two displays in the Main module, and 0 0 in the doSomething module.
Design pseudocode for an If-Then-Else statement that assigns 0 to the variable b if the variable a is less than 10.
Otherwise, it should assign 99 to the variable b.
Your Answer:
If a < 10 Then:
b = 0
else b = 99
End If
Write Python code that asks the user for a product name, the cost of the product and the quantity of the product purchased. Display the product name and the total cost of the purchase.
You do not have to create a function or call a function for this problem.
Your Answer: def productName():
productName = float(input(‘Enter the name of the product: ‘))
return productName
def productCost():
productCost = float(input(‘Enter the cost of the product: ‘))
return productCost
def productQuantity():
productQuantity = float(input(‘Enter the quantity of the product: ‘))
return productQuantity
def totalCost(productName, productQuantity, productCost):
totalCost = productQuantity * productCost
print(‘The name of the product is: )productName
print(‘The total cost of the product is ‘)totalCost
COMMENT: These functions will work, but you also need a main module that will call them in the order you need.
Write Python code that has a function called “doubleMe”. The function requires that an integer value is passed to it when called. The function should double the integer value and return the result.
Write an additional Python statement that calls function “doubleMe” and passes it a 10. The result returned from the function should be stored in a variable called “answer”.
Your Answer: def main():
integerAnswer = integerValue
def doubleMe():
doubleMe = integerValue * 2
integerValue = float(input(‘Enter the number: ‘))
input number
print(“The answer is: “)integerAnswer
end main()
COMMENT: main() never calls doubleMe therefore this script does nothing since we haven’t set values for integerValue or called any other modules.
Write Python code that tests the integer variable called “month”. Based on the value, display the month name. Valid values are: 1 (display January), 2 (display February), and 3 (display March) . Use if/elif statements, not all if statements.
You do not have to create a function or call a function for this problem.
Your Answer: def month():
if month = 1:
print(“The month is January”)
elif month = 2:
print(“The month is February”)
elif month = 3
print(“The month is March”)
end if
Write Python code that displays “Speed is OK” if the variable “speed” is within the range 24 to 56.
If “speed” holds a value outside the range, display “Speed is abnormal”.
You do not have to create a function or call a function for this problem.
Your Answer: def speed():
if speed >= 24 AND speed <= 56
print(“Speed is OK”)
elif speed < 24 OR speed > 56
print(“Speed is abnormal”)
end if
Which of the following is the structure that causes a statement or set of statements to execute repeatedly?
Repetition
Which type of loop uses a Boolean expression to control the number of times a loop repeats?
condition-controlled
Statements that appear between the While and End While statements are known as the __________.
loop body
A __________ represents a special value that marks the end of a list of values.
sentinel
If an expression is False, the __________ operator will return True.
NOT
How many times would the following loop iterate?
For j = 1 To 5 Step 2
Display j
End For
3