Intro to Python #2
What is the result of the following calculation? 8 + 3 * (9 - 5) / 2 Multiple choice question. 10 14 15 22
14
What would be the display after the following code is executed? number = 1 while(number < 4): print(number * 2) number = number + 1 Multiple choice question. 2 4 6 1 2 3 2 4 6 8 Nothing since number starts out less than the test condition
2 4 6
Which of the following are considered floating-point numbers? Multiple select question. 8.0 -22.98 345 17.900
8.0 -22.98 17.900
Use your understanding of logical operators to help determine which of the following will result in False? Multiple select question. 9 > 10 or 12 < 3 2 == 3 or 5 == 5 (5 + 7) > 10 and (6 + 2) < 9 2 == 3 and 5 == 5
9 > 10 or 12 < 3 2 == 3 and 5 == 5
Select the true statements about flowcharts. Multiple select question. A flowchart is a diagram. There are only three symbols that can be used in a flowchart. Flowcharts are used to represent the flow of execution of a program. Flowcharts show the programmer what will happen at various branch points.
A flowchart is a diagram. Flowcharts are used to represent the flow of execution of a program. Flowcharts show the programmer what will happen at various branch points.
Which of the following statements are true about the IDLE editor?
A program created in the editor will run in the shell. The editor works like a simple word processor, but it also allows Python to compile and run source code. To write an entire Python program, you must use the editor and not the shell.
Which of the following are needed to create a function? Multiple select question. A set of parentheses with any necessary arguments The keyword def A question mark at the end The function name
A set of parentheses with any necessary arguments The keyword def The function name
Students in a programming class have ID numbers from 1 through 15. They are assigned to groups based on their ID numbers. What is wrong with the following code that tells students which group they will be in? if(number > 0 and number < 5): print("You're in the blue group.") elif(number > 5 and number < 10): print("You're in the green group.") elif(number >= 10 and number <= 15): print("You're in the red group.") else: print("You are not in this class")
A student with ID number 5 will not be in any group.
Select the true statements about ASCII code. Multiple select question. ASCII code can compare long strings of text as well as single characters. The ASCII representation of uppercase A is the same as lowercase a. ASCII code is used to represent all the upper- and lowercase characters as well as digits 0 through 9. ASCII code is used for alphabetizing values in programming.
ASCII code can compare long strings of text as well as single characters. ASCII code is used to represent all the upper- and lowercase characters as well as digits 0 through 9. ASCII code is used for alphabetizing values in programming.
What is the purpose of ASCII code in character comparison, as explained in the text? Multiple select question. ASCII code represents characters as numeric values. ASCII code ensures case-insensitive character comparison. ASCII code allows for efficient numeric value comparison. ASCII code helps computers determine the alphabetical order of characters.
ASCII code represents characters as numeric values. ASCII code helps computers determine the alphabetical order of characters.
The standard representation of characters in programming is called Blank______. Multiple choice question. ASCII code, which stands for American Simple Code for Interchanging Information ASCII code, which stands for American Standard Code for Information Interchange UCII, which stands for Unified Code Two Unitcode
ASCII code, which stands for American Standard Code for Information Interchange
Select the true statements about an IDE. Multiple select question. An IDE includes a source code editor. An IDE is a software application. IDE stands for Integrated Development Environment. Python programmers never use an IDE.
An IDE includes a source code editor. An IDE is a software application. IDE stands for Integrated Development Environment.
What is each item in a list called? Multiple choice question. An element A tuple A variable An array
An element
Which of the following statements are true about dual-alternative selection structures?
Another term for a dual-alternative structure is an if-else clause. Only one block of statements will be executed in a dual-alternative structure. One block of statements is executed if the condition is True, and a different block of statements is executed if the condition is False.
Given the following code, which has a variable named light, what will be displayed if light has the value "yellow"? if(light == "green"): print("You are good to go!") else: print("Better stay put!") print("Drive safely.") Multiple choice question. You are good to go! Drive safely. Better stay put! Drive safely. Better stay put!
Better stay put! Drive safely.
What is the role of built-in functions in Python, as described in the text? Multiple select question. Built-in functions instruct the program to perform specific tasks. Built-in functions are only used to display text on the screen. Built-in functions include functions like abs(), sort(), and len(). Built-in functions can only perform simple tasks.
Built-in functions instruct the program to perform specific tasks. Built-in functions include functions like abs(), sort(), and len().
What is the difference between a built-in function and a function created by a programmer?
Built-in functions perform specific tasks. Programmers can create their own functions to do other tasks, as needed. The code for a built-in function is included with the Python software and is hidden from programmers using that software.
Which of the following are alternate ways to refer to a selection structure? Multiple select question. Sequential construct Conditional statement If-statement Selection construct
Conditional statement If-statement Selection construct
Which of the following situations would best be handled by an if-elif multiple-alternative structure? Multiple choice question. Displaying the sales tax of an item Displaying four possible prizes based on a user's total purchase amount Displaying a train's scheduled departure times Displaying grades that are either Pass or Fail
Displaying four possible prizes based on a user's total purchase amount
Which of the following statements are true about functions? Multiple select question. Each function normally performs a single task. When a specific task is needed, the function that does that task is called. Functions are required of all programs, regardless of the length of the program. Functions allow programmers to break up code into manageable tasks.
Each function normally performs a single task. When a specific task is needed, the function that does that task is called. Functions allow programmers to break up code into manageable tasks.
Which of the following are ways to identify comments in Python? Multiple select question. Enclose the commented line or lines between two sets of three apostrophes (' ' '). Enclose the commented line or lines between two sets of three double quotes (" " "). Preface the comment with the Python keyword comment. Use the hashtag symbol (#).
Enclose the commented line or lines between two sets of three apostrophes (' ' '). Enclose the commented line or lines between two sets of three double quotes (" " "). Use the hashtag symbol (#).
Computers use relational operators to compare two values, variables, or expressions. An expression consists of several values or variables and may combine values and variables. Based on this information, the result of the expression (5 + 3) >= 15 is Blank______. Multiple choice question. False Program error -10 True
False
A single-alternative structure consists of an if clause with a condition. If the result of the condition is True, a block of statements is executed. If the condition is False, nothing is done and the program continues to the next statement after the selection structure. Given the following code, what will be displayed if the user is 17 years old? if(age >= 18): print("You are eligible to vote.") print("Goodbye") Multiple select question. Goodbye You are eligible to vote. Goodbye print("Goodbye" You are eligible to vote.
Goodbye
Given the following loop, what will be the display after the loop executes? index = 1 while(index <= 3): print("Happy day!") index = index + 1 Multiple choice question. Happy day! Happy day! Happy day! Happy day! Happy day! Happy day! Happy day! Happy day! Happy day! Happy day!
Happy day! Happy day! Happy day!
Which of the following are true about IDLE?
IDLE is an IDE. IDLE comes packaged with a Python download. IDLE is free.
Which of the following are needed by every program? Multiple select question. Instructions A form of input A way to display results A monitor
Instructions A form of input A way to display results
In the following program, which line is the processing line? 1. num_1 = 5 2. num_2 = 3 3. sum = num_1 + num_2 4. print ("The sum is ", sum) Multiple choice question. Line 1 Line 2 Line 3 Line 4
Line 3
Which of the following statements about pseudocode are true? Multiple select question. For pseudocode to be useful, it must initially contain all the details about the program. Most programmers use both pseudocode and flowcharts when starting to design a program. Pseudocode is not written in a specific language. Pseudocode consists of pictures that represent the flow of a program.
Most programmers use both pseudocode and flowcharts when starting to design a program. Pseudocode is not written in a specific language.
Select all of the following that are considered integers. Multiple select question. 7.0 Negative whole numbers Positive whole numbers Zero
Negative whole numbers Positive whole numbers Zero
What is the significance of nesting control structures? Multiple select question. Nesting control structures is not a common practice in programming. Nesting control structures allows for more complex program behavior. Nested control structures can only include loops within loops. Complex combinations of control structures are possible through nesting.
Nesting control structures allows for more complex program behavior. Complex combinations of control structures are possible through nesting.
______ is how the computer communicates results. Multiple choice question. Graphics Input Imaging Output
Output
Which symbol in a flowchart represents input and output? Multiple choice question. Oval Diamond Rectangle Parallelogram
Parallelogram
Which of the following must be used by all programs?
Processing Input Output
The Blank______ is a methodology used by programmers to develop a program. Multiple choice question. Program Design Complex Program Development Cycle Syntax Development Cycle Programming Development Coordination Cycle
Program Development Cycle
______ use(s) short phrases to describe the outline of a program. Multiple choice question. IDLE Flowcharts Pseudocode Syntax
Pseudocode
The three basic structures are Blank______. Multiple select question. Syntax Repetition Selection Sequence
Repetition Selection Sequence
What are the characteristics and purposes of repetition structures (loops) in computer programming? Multiple select question. Repetition structures involve a block of statements executed under certain conditions. In a repetition structure, the loop body is executed only once. The value in the test condition can change during the loop's iterations. Loops end when the value in the test condition remains constant.
Repetition structures involve a block of statements executed under certain conditions. The value in the test condition can change during the loop's iterations.
Which of the following are popular methods data from a program can be output? Multiple select question. Sent to the Cloud Sent to a fax machine Sent to a file Displayed on a screen
Sent to the Cloud Sent to a file Displayed on a screen
What type of loop ends when a specific value is entered by the user or by something in the code? Multiple choice question. Sentinel-controlled loop if-elif loop Repetitive loop Counter-controlled loop
Sentinel-controlled loop
What are the three fundamental constructs that form the basis of virtually all computer programs? Multiple choice question. Compilation, execution, and debugging Syntax, semantics, and variables Sequence, selection, and repetition Data, algorithms, and functions
Sequence, selection, and repetition
Which of the following statements are true about a program that only includes sequential structures. Multiple select question. Branch points are encountered in decision-making scenarios. Handling of branch points is consistent across all programs. Sequential structures do not involve any repetition. Sequential structures involve decision making. Sequential programming prohibits all forms of branching.
Sequential structures do not involve any repetition. Sequential programming prohibits all forms of branching.
In a computer program where the characters are exactly as shown, which word would be listed first and why? word1 = "kangaroo" word2 = "Teddy" Multiple choice question. Teddy would be first because uppercase letters have smaller ASCII codes than lowercase. kangaroo would be first because "k" comes before "T" in the alphabet. kangaroo would be first because the computer would compare word1 and word2 and 1 comes before 2. Teddy would be first because it is a shorter string than kangaroo.
Teddy would be first because uppercase letters have smaller ASCII codes than lowercase.
In a Python print() statement, what types of data can be displayed? Multiple choice question. Only numbers Text only Text, numbers, and variables Only variables
Text, numbers, and variables
What are the characteristics and hierarchy of logical operators in computer programs? Multiple select question. The "and" operator results in True if both simple conditions are True. Logical operators are evaluated before mathematical operators. The "or" operator always results in False. The "not" operator reverses the result of a simple condition.
The "and" operator results in True if both simple conditions are True. The "not" operator reverses the result of a simple condition.
What are the key characteristics of a single-alternative structure? Multiple select question. The condition must be enclosed in parentheses. If the condition is True, a block of statements is executed. Statements executed when the condition is True must be indented. If the condition is False, a block of statements is executed.
The condition must be enclosed in parentheses. If the condition is True, a block of statements is executed. Statements executed when the condition is True must be indented.
What is the purpose of the line return sum in the add_values() function shown here? def add_values(X, Y) sum = X + Y return sum Multiple choice question. The line return sum terminates the execution of the function. The line return sum is used to calculate the sum of X and Y. The line return sum defines a new variable named "sum." The line return sum allows the result of the function to be sent back to the code that called it.
The line return sum allows the result of the function to be sent back to the code that called it.
How does Python locate a CSV file for processing?
The program may ask the user to provide the path to the CSV file. The programmer specifies the path to the CSV file in the code.
In a for loop, which parts of the loop are defined in a single statement? Multiple select question. The output The test condition The increment or decrement of the test condition The initial condition
The test condition The increment or decrement of the test condition The initial condition
Which of the following statements are true about how numbers are processed in a computer? Multiple select question. It takes more space to store an integer than to store a floating-point number. The type of mathematical operations that can be performed on numeric data depends on the numbers' data types. Numbers and characters are treated differently in memory. It takes more space to store a floating-point number than to store an integer.
The type of mathematical operations that can be performed on numeric data depends on the numbers' data types. Numbers and characters are treated differently in memory. It takes more space to store a floating-point number than to store an integer.
Which of the following statements are true about variables?
The value of a variable is stored in the variable's location in computer memory. The value of a variable can change as the program runs. It is possible to join the value of one variable with the value of another variable to create a new variable.
What is wrong with the following code that calculates the cost of an item with tax? tax = 0.06 cost = float(input("How much does your item cost? ")) while(cost != 0): new_cost = cost + (cost * tax) print("Total cost is $ ", new_cost) print("Goodbye") Multiple choice question. The calculation on line 4 is incorrect. The value of cost never changes so this will be an infinite loop. The tax amount is incorrect. Line 6 should be indented.
The value of cost never changes so this will be an infinite loop.
Which of the following statements are true of relational operators? Multiple select question. There are six relational operators. The result of any comparison between relational operators is always either True or False. Relational operators are used to compare two values, variables, or expressions. There are five relational operators.
There are six relational operators. The result of any comparison between relational operators is always either True or False. Relational operators are used to compare two values, variables, or expressions.
What is the purpose of a sentinel-controlled loop?
To execute a block of statements repeatedly To prompt the user for input until a sentinel value is entered
What is the primary purpose of including comments in code? Multiple choice question. To provide explanations for different parts of the code To prevent other developers from understanding the code To write alternative code for future use To improve the program's execution speed
To provide explanations for different parts of the code
Which of the following are true statements about IDLE? Multiple select question. To run a program created in the editor, you must first save it as a .py file. IDLE allows you to add emojis to your programs. IDLE will tell you of runtime errors when you run a program. The editor highlights syntax errors as you write code.
To run a program created in the editor, you must first save it as a .py file. IDLE will tell you of runtime errors when you run a program. The editor highlights syntax errors as you write code.
Which of the following are true about variable names? Multiple select question. Variable names cannot include spaces. Variable names must be either all upper or all lowercase. Variable names are case sensitive. Variable names may contain numbers but cannot begin with a number.
Variable names cannot include spaces. Variable names are case sensitive. Variable names may contain numbers but cannot begin with a number.
In Python, a list is Blank______. Multiple choice question. a data file a column in a database a group of related items imported from a database
a group of related items
A single-alternative structure consists of an if clause with a condition. If the result of the condition is True, a block of statements is executed. If the condition is False, nothing is done and the program continues to the next statement after the selection structure. Given the following code, what is the test condition? if(age >= 18): print("You are eligible to vote.") print("Goodbye") Multiple choice question. age if(age >= 18): print("You are eligible to vote.") age >= 18
age >= 18
When you download Python you get Blank______. Multiple select question. an executable file that must be installed. the IDLE program both Python 2 and Python 3. an email with an attached file.
an executable file that must be installed. the IDLE program
When a decision is made and a specific path of instructions is followed, this is called a Blank______. Multiple choice question. repetition structure loop branch point sequence
branch point
Each Blank______ in the computer's memory is represented by its ASCII code. Multiple choice question. numeric value character string word
character
When you go to www.python.org to download Python, you must Blank______.
choose an operating system.
In a(n) Blank______ loop, the body of the loop is executed a fixed number of times. Multiple choice question. if-elif loop sentinel-controlled loop repetitive loop counter-controlled
counter-controlled
What is the name of the Python module that must be imported for Python to work on data in a CSV file? Multiple choice question. NumPy Excel Seaborn csv
csv
The stages of the PDLC are Blank______. Multiple choice question. design, code, and test design, code, test, and revise define, design, code, and test define, design, code, test, and revise
define, design, code, test, and revise
A computer is content to process programming instructions internally, but output is needed by
humans
In Python, a prompt takes the form of a(n) ___________. Multiple choice question. screenshot value syntax statement input request
input request
Computers process instructions Blank______. Multiple choice question. on a monitor with a calculator internally randomly
internally
The ability of a computer to do a task over and over is known as a Blank______. Multiple choice question. function loop comparison search
loop
Which of the following are built-in Python functions? Multiple select question. print() input() scope() abs()
print() input() abs()
The work done by a computer program is called Blank______. Multiple choice question. input the results processing Python
processing
In a program, a Blank______ tells the user what input is needed. Multiple choice question. prompt number variable file
prompt
To specify that a random number should be an integer, Python programmers use the Blank______ function. Multiple choice question. randomize() import randint() random()
randint()
Computers use Blank______ to make comparisons.
relational operators
In order to process data, a computer program needs Blank______. Multiple choice question. a file user input variables with values and instructions Python
variables with values and instructions