CS LAB

Comments in Python begin with the # character.
True
False
Click the card to flip 👆
1 / 110
Terms in this set (110)
Since a named constant is just a variable, it can change any time during a program's execution. True FalsefalseWhat is the informal language, used by programmers use to create models of programs, that has no syntax rules and is not meant to be compiled or executed? a. flowchart b. algorithm c. source code d. pseudocodepseudocodeA(n) __________ is a diagram that graphically depicts the steps that take place in a program? a. flowchart b. algorithm c. source code d. pseudocodeflowchartThe __________ function reads a piece of data that has been entered at the keyboard and returns that piece of data, as a string, back to the program. a. input() b. output() c. eval_input() d. str_input()input()The line continuation character is a a. # b. % c. & d. \\Which mathematical operator is used to raise 5 to the second power in Python? a. / b. ** c. ^ d. ~**In a print statement, you can set the __________ argument to a space or empty string to stop the output from advancing to a new line. a. stop b. end c. separator d. newLineendAfter the execution of the following statement, the variable sold will reference the numeric literal value as (n) __________ data type sold = 256.752 a. int b. float c. str d. currencyfloatAfter the execution of the following statement, the variable price will reference the value __________.price = int(68.549) a. 68 b. 69 c. 68.55 d. 68.668What is the output of the following statement? print('I\'m ready to begin') a. Im ready to begin b. I\'m ready to begin c. I'm ready to begin d. 'I\'m ready to begin'I'm ready to beginWhat is the output of the following statement, given that value1 = 2.0 and value2 = 12?print(value1 * value2) a. 24 b. value1 * value2 c. 24.0 d. 2.0 * 1224.0What is the output of the following statement?print('The path is D:\\sample\\test.') a. 'The path is D:\\sample\\test.' b. The path is D:\\sample\\test. c. The path is D\\sample\\test. d. The path is D:\sample\test.The path is D:\sample\testWhat is the output of the following statement?print ('One' 'Two' 'Three') a. One Two Three b. One Two Three c. OneTwoThree d. Nothing—This statement contains an error.OneTwoThreeThe __________ built-in function is used to read a number that has been typed on the keyboard. a. input() b. read() c. get() d. keyboard()input()What is the output of the following code? val = 123.456789print(f'{val:.3f}') a. 123 b. 123.457 c. 123.456 d. 123.456789123.457What is the output of the following code? val = 123456.789print(f'{val:,.2f}') a. 123456.79 b. 123456.78 c. 123,456.78 d. 123,456.79123,456.79Which of the following will display 20%? a. print(f'{20:.0%}') b. print(f'{0.2:.0%}') c. print(f'{0.2 * 100:.0%}') d. print(f'{0.2:%}')print(f'{0.2:.0%}')What symbol is used to mark the beginning and end of a string?a. a slash (/) b. an asterisk (*) c. a quote mark (") d. a comma (,)a quote mark (")To use Python's turtle graphics, you must include which of the following statements in your program? a. import turtle_module b. import turtle_graphics c. import turtle d. import Turtleimport turtleThe Python turtle is initially positioned in the __________ of a graphics window and it first appears, by default, to be heading __________. a. center, up b. top left corner, east c. bottom left corner, down d. center, eastcenter, eastYou can use the _______________ turtle graphics command to get numeric input from the user and assign it to a variable. a. turtle.numinput b. turtle.getnum c. turtle.inputnum d. turtle.dialogturtle.numinputSelect all that apply. Which of the following are steps in the program development cycle? a. design the program b. write the code and correct syntax errors c. test the program d. correct logic errorsdesign the program write the code and correct syntax errors test the program correct logic erroeselect all that apply. Assume you are writing a program that calculates a user's total order cost that includes sales tax of 6.5%. Which of the following are advantages of using a named constant to represent the sales tax instead of simply entering 0.065 each time the tax is required in the code? a. It will be easier for another programmer who may need to use this code to understand the purpose of the number wherever it is used in the code. b. If the tax amount changes to 7.0%, the value will only have to be changed in one place. c. It allows the end-user to always see the value of the sales tax. d. It avoids the risk that any change to the value of sales tax will be made incorrectly or that an instance of the tax value might be missed as might occur if the number had to be changed in multiple locations.It will be easier for another programmer may need to use this code to understand the purpose of the number wherever it is used in the code if the tax amount changes to 7.0% the value will only have to be changed in one place it avoids the risk that any change to the value of sales tax will be made incorrectly or that an instance of the tax value might be missed as might occur if the number had to be changed in multiple locations___________ are notes of explanation that document lines or sections of a program.commentsThe % symbol is the remainder operator, also known as the ___________ operator.modulus or modA(n) __________ character is a special character that is preceded with a backslash (\), appearing inside a string literal.escapeThe __________ specifier is a special set of characters that specify how a value should be formatted.formattingWhen applying the .3f formatting specifier to the number 76.15854, the result is __________.76.159A(n) __________ is a single task that the program must perform in order to satisfy the customer.software requirementIn the expression 12.45 + 3.6, the values to the right and left of the + symbol are the __________.operandsA(n) __________ is a name that represents a value stored in the computer's memory.variablePython uses __________ to categorize values in memory.data typesWhen the + operator is used with two strings, it performs string __________.concatenationA __________ is a name that represents a value the cannot be changed during a program's execution.named constantsThe Python language is not sensitive to block structuring of code. True FalseFalseThe if statement causes one or more statements to execute only when a Boolean expression is true. True FalsetruePython allows you to compare strings, but it is not case sensitive. True FalsefalseNested decision statements are one way to test more than one condition. True FalseTruePython uses the same symbols for the assignment operator as for the equality operator. True FalsefalseThe not operator is a unary operator which must be used in a compound expression. True FalsefalseShort -circuit evaluation is only performed with the not operator. true falsefalseExpressions that are tested by the if statement are called Boolean expressions. true falsetrueDecision structures are also known as selection structures. true falsetrueAn action in a single alternative decision structure is performed only when the condition is true. true falsetrueThe following statement will check to see if the turtle's pen color is 'green':if turtle.pencolor() = 'green': true falsefalseThe following code snippet will change the turtle's pen size to 4 if it is presently less than 4:if turtle.pensize() < 4: turtle.pensize(4) true falsetrueA(n) __________ structure is a logical design that controls the order in which a set of statements execute. a. function b. control c. sequence d. iterationcontrolThe decision structure that has two possible paths of execution is known as a. single alternative b. double alternative c. dual alternative d. two alternativedual alternativeMultiple Boolean expressions can be combined by using a logical operator to create __________ expressions. a. sequential b. logical c. compound d. mathematicalcompoundWhen using the __________ logical operator, one or both of the subexpressions must be true for the compound expression to be true. a. or b. and c. not d. maybeorWhich logical operators perform short-circuit evaluation? a. or, not b. not, and c. or, and d. and, or, notor, andWhich of the following is the correct if clause to determine whether y is in the range 10 through 50, inclusive? a. if 10 < y or y > 50: b. if 10 > y and y < 50: c. if y >= 10 and y <= 50: d. if y >= 10 or y <= 50:if y >= 10 and y <= 50:A Boolean variable can reference one of two values which are a. yes or no b. True or False c. T or F d. Y or Ntrue or falseWhat is the result of the following Boolean expression, given that x = 5, y = 3, and z = 8? x < y or z > x a. True b. False c. 8 d. 5trueWhat is the result of the following Boolean expression, given that x = 5, y = 3, and z = 8? x < y and z > x a. True b. False c. 8 d. 5falseWhat is the result of the following Boolean expression, given that x = 5, y = 3, and z= 8? not (x < y or z > x) and y < z a. True b. False c. 8 d. 5falseWhat does the following expression mean? x <= y a. x is less than y b. x is less than or equal to y c. x is greater than y d. x is greater than or equal to yx is less than or equal to yWhich of the following is the correct if clause to determine whether choice is anything other than 10? a. if choice != 10: b. if choice != 10 c. if choice <> 10: d. if not(choice < 10 and choice > 10):if choice != 10:When using the __________ logical operator, both subexpressions must be true for the compound expression to be true. a. or b. and c. not d. either or or andand14. In Python the __________ symbol is used as the not-equal-to operator. a. == b. <> c. <= d. !=!=In Python the __________ symbol is used as the equality operator. a. == b. <> c. <= d. !===Which of the following will hide the turtle if it is visible? a. if turtle.isvisible(): turtle.invisible() b. if turtle.isvisibleturtle.hideturtle() c. turtle.isvisible():turtle.hide() d. if turtle.isvisible(): turtle.hideturtle()if turtle.isvisible(): turtle.hideturtle()Which of the following will determine if the turtle's pen is up and will change it to down if that is the case? a. if turtle.isup(): turtle.isdown() b. if turtle.isdown turtle.penup() c. if not(turtle.isdown()): turtle.pendown() d. if not(turtle.penup()) turtle.penup()if not(turtle.isdown()): turtle.pendown()The ___________ statement is used to create a decision structure.ifIn flowcharting, the __________ symbol is used to represent a Boolean expression.diamondA(n) __________ decision structure provides only one alternative path of execution.single alternativen a decision structure, the action is ___________ executed because it is performed only when a specific condition is true.conditionallyA(n) __________ operator determines whether a specific relationship exists between two values.relationalA(n) __________ statement will execute one block of statements if its condition is true or another block if its condition is false.if-elsePython provides a special version of a decision structure known as the __________ statement, which makes the logic of the nested decision structure simpler to write.if-elif-elseThe logical __________ operator reverses the truth of a Boolean expression.notBoolean variables are commonly used as __________ to indicate whether a specific condition exists.flagsA(n) ___________ expression is made up of two or more Boolean expressions.compoundThe turtle.isdown() function returns ___________ if the turtle's pen is down.trueReducing duplication of code is one of the advantages of using a loop structure. true falsetrueA good way to repeatedly perform an operation is to write the statements for the task once and then place the statements in a loop that will repeat as many times as necessary. true falsetrueIn a flowchart, both the decision structure and the repetition structure use the diamond symbol to represent the condition that is tested. true falsetrueThe first line in a while loop is referred to as the condition clause. true falsefalseIn Python, an infinite loop usually occurs when the computer accesses an incorrect memory address. true falsefalseBoth of the following for clauses would generate the same number of loop iterations. for num in range(4): for num in range(1, 5): true falsetrueThe integrity of a program's output is only as good as the integrity of its input. For this reason, the program should discard input that is invalid and prompt the user to enter valid data. true falsetrueFunctions can be called from statements in the body of a loop and loops can be called from within the body of a function. true falsefalseIn a nested loop, the inner loop goes through all of its iterations for each iteration of the outer loop. true falsetrueTo get the total number of iterations in a nested loop, add the number of iterations in the inner loop to the number in the outer loop. true falsefalseA while loop is called a pretest loop because the condition is tested after the loop has had one iteration. true falsefalseIn order to draw an octagon with turtle graphics, you would need a loop that iterates eight times. true falsetrueWhat type of loop structure repeats the code a specific number of times? a. condition-controlled loop b. number-controlled loop c. count-controlled loop d. Boolean-controlled loopcount-controlled loopWhat type of loop structure repeats the code based on the value of Boolean expression? a. condition-controlled loop b. number-controlled loop c. count-controlled loop d. Boolean-controlled loopcondition-controlled loopWhat are the values that the variable num contains through the iterations of the following for loop? for num in range(2, 9, 2): a. 2, 3, 4, 5, 6, 7, 8, 9 b. 2, 5, 8 c. 2, 4, 6, 8 d. 1, 3, 5, 7, 92, 4, 6, 8What are the values that the variable num contains through the iterations of the following for loop? for num in range(4): a. 1, 2, 3, 4 b. 0, 1, 2, 3, 4 c. 1, 2, 3 d. 0, 1, 2, 30, 1, 2, 3Which of the following is not an augmented assignment operator? a. *= b. /= c. += d. <=<=A variable used to keep a running total is called a(n) a. accumulator b. total c. running total d. summeraccumulator__________ is the process of inspecting data that has been input into a program in order to ensure that the data is valid before it is used in a computation a. Input validation b. Correcting data c. Data validation d. Correcting inputinput validationA(n) __________ structure is a structure that causes a statement or a set of statements to execute repeatedly. a. sequence b. decision c. module d. repetitionrepetitionThe first operation is called the __________ and its purpose is to get the first input value that will be tested by the validation loop. a. priming read b. first input c. loop set read d. loop validationpriming readWhen will the following loop terminate? while keep_going != 999: a. when keep_going refers to a value less than 999 b. when keep_going refers to a value greater than 999 c. when keep_going refers to a value equal to 999 d. when keep_going refers to a value not equal to 999when keep_going refers to a value equal to 999In Python, a comma-separated sequence of data items that are enclosed in a set of brackets is called a. sequence b. variable c. value d. listlistIn Python, the variable in the for clause is referred to as the __________ because it is the target of an assignment at the beginning of each loop iteration. a. target variable b. loop variable c. for variable d. count variabletarget variableWhich of the following represents an example to calculate the sum of numbers (that is, an accumulator), given that the number is stored in the variable number and the total is stored in the variable total? a. total + number = total b. number += number c. total += number d. total = numbertotal += numberWhat will be displayed after the following code is executed?total = 0for count in range(1,4): total += countprint(total) a. 1 3 6 b. 5 c. 1 4 d. 66