COSC-1315-007 Study Guide

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

B. via a command prompt

A console application runs A. through a browser B. via a command prompt C. with a GUI D. through another application

A. once for each integer in the collection returned by the range() function

A for loop that uses a range() function is executed A. once for each integer in the collection returned by the range() function B. until the for condition is equal to the value returned by the range() function C. while the for condition is less than the value returned by the range() function D. until the range() function returns a false value

D. is defined outside of all functions

A global variable A. is defined inside the main() function B. cannot be modified inside a function C. cannot be accessed from within a function D. is defined outside of all functions

A. inside a function

A local variable is defined A. inside a function B. inside the main() function C. inside an if statement D. outside of all functions

D. An exception

A runtime error is also known as A. a syntax error B. a logical error C. a violation D. an exception

A. [['Mike' ,98,'A'],['Lizzy',73,'C'],['Joel',88,'B+'],['Anne',93,'A']]

A. B. D. C.

A. 1

A. 1 B. 1.533333 C. 0.533333 D. 8

C. 5.0

A. 2 B. 4.5 C. 5.0 D. 3

D. these variables don't exist

A. 9,8 B. 5,6 C. 4,2 D. these variables don't exist

B. assigns a value to a variable and evaluates a Boolean expression

An assignment expression does which of the following? A. assigns a Boolean expression to a variable B. assigns a value to a variable and evaluates a Boolean expression C. gets user input from the console, assigns the value to a variable, and evaluates a Boolean expression D. gets user input from the console and assigns the value to a variable

B. number = random.radint(0, 1)

Assuming the random module has been imported into its default namespace, which of the following could be used to simulate a coin toss where 0 = heads and 1 = tails A. number = random.coin() B. number = random.radint(0, 1) C. number = random.radint(0, 2) D. number = random.random()

A. import the module

Before you can use a standard module like the random module, you need to A. import the module B. import the module into a custom namespace C. import the module into the global namespace D. import the module into its default namespace

C. The product is 6

For the following code, what will the result be if the user enters 4 at the prompt? A. The product is 1 B. The product is 4 C. The product is 6 D. The product is 24.

D. the product is 24

For the following code, what will the result be if the user enters 4 at the prompt? A. the product is 1 B. the product is 4 C. the product is 6 D. the product is 24

B. 1, 3, 6, 10,

For the following code, what will the result be if the user enters 5 at the prompt? A. 10, B. 1, 3, 6, 10 C. 1, 3, 6, 10, 16 D. 1, 2, 3, 4, 5,

B. 1, 3, 6, 10,

For the following code, what will the result be if the user enters 5 at the prompt? A. 10, B. 1, 3, 6, 10, C. 1, 3, 6, 10, 16, D. 1, 2, 3, 4, 5,

D. w, x, y, z = numbers

Give the tuple that follows, which of the following assigns the values in the tuple to variables? numbers = (22, 33, 44, 55) A. for items in numbers: item[i] = numbers[i] B. w, x, y, z, = numbers.unpack() C. w = numbers x = numbers y = numbers z = numbers D. w, x, y, z = numbers

C. change line 5 to: pay = (40 * rate) + (hours - 40) * rate * 1.5)

Given the following code, if the user worked 45 hours at $10.00/hour, the output is shown A. change lines 2 and 3 to receive integer values instead of floating-point B. change line 4 to: if (hours > 40) or (rate < 15) : C. change line 5 to: pay = (40 * rate) + (hours - 40) * rate * 1.5) D. change line 8 to: print("Your pay is: $ ', str(round(pay, 2)))

B. Joel

Given the following list, what is the value of names[2]? A. Mike B. Joel C. Anne D. None, improper assignment of "Donald Duck' due to space in the name

D. 6

How many times will "Hi again!" be displayed after the following code executes? A. 2 B. 12 C. 5 D. 6

B. a name collision occurs

If you import two modules into the global namespace and each has a function named get_value(), A. an error occurs B. a name collision occurs C. an exception occurs D. the program crashes

B. a pass statement

If you want to code an if clause but you don't want to perform any action, you can code A. an end statement B. a pass statement C. a break statement D. a skip statement

A. before the loop is executed

In a while loop, the Boolean expression is tested A. before the loop is executed B. after the loop is executed C. both before and after the loop is executed D. until it equals the current loop value

D. all of the above

Python comments A. are ignored by the compiler B. can be used to document what a program or portion of code does C. can be used so certain lines of code are not executed during testing D. all of the above

D. all of the above

Python is considered a good first language to learn because A. it has a simple syntax B. it has most of the features of traditional programming languages C. it is open source D. all of the above

D. All of the above

Python is considered a good first language to learn because A. it has simple syntax B. it has most of the features of traditional programming languages C. it is open source D. all of the above

A. first, last

Refer to Code Example 4-1: What arguments are defined by the get_username() function? A. first, last B. s, first, last C. first_name, last_name D. username

A. get_username()

Refer to Code Example 4-1: What function is called first when the program runs? A. get_username() B. main() C. if__name__ == "__main__" D. input("Enter your first name: ")

C. 4

Refer to Code Example 4-2: What value is passed to the height argument by the call to the get_volume() function? A. 2 B. 3 C. $ D. 5

D. The answer is 24

Refer to Code Example 4-4: When this code runs, what does it print to the console? A. The answer is 28 B. The answer is 12 C. The answer is 7 D. The answer is 24

A. The input statement on line 11 gets a variable named grade but sends in an undefined variable named score on line 12

Refer to Code Example 5-2: What is the error in the main() function A. The input statement on line 11 gets a variable named grade but sends in an undefined variable named score on line 12 B. The input statement on line 11 does not define grades as an int C. The function call on line 12 should send in fname and lname as arguments, not last and first D. There are no errors in main()

B. systems

The _________ software for a computer provides the software that's needed for running applications A. application B. systems C. operation D. GUI

B. Systems

The __________ software for a computer provides the software that's needed for running applications. A. application B. systems C. operation D. GUI

C. an if statement that calls the main() function only if the current module is the main module

The best way to call the main() function of a program is to code A. main() B. an if statement that calls the main() function only if the function exists C. an if statement that calls the main() function only if the current module is the main module D. a while statement that calls the main() function in each loop

C. main memory

The data in _______ is lost when an application ends. A. the application software B. disk storage C. main memory D. the CPU

C. Main Memory

The data in _________ is lost when an application ends A. the application software B. disk storage C. main memory D. the CPU`

B. Disk Storage

The data in ___________ is persistent so it is not lost when an application ends A. the application software B. disk Storage C. main memory D. the CPU

B. disk storage

The date in _________ is persistent so it is not lost when an application ends. A. the application software B. disk storage C. main memory D. the CPU

D. a shebang line

The following is an example of _________. A. Java code B. bytecode C. source code D. a shebang line

The following is an example of ___________. A. java code B. bytecode C. source code D. shebang Line

The following is an example of ___________. A. java code B. bytecode C. source code D. shebang Line

C. debugging

The goal of _____ is to fix all the errors in a program A. editing B. testing C. debugging D. interpreting

B. testing

The goal of _________ is to find all the errors in a program A. editing B. testing C. debugging D. interpreting

D. is immutable

The primary difference between a tuple and a list is that a tuple A. has a limited range B. is indexed starting from 1 C. is mutable D. is immutable

D. calls a function that returns an aggregate value

The reduce() function A. displays the items in a list B. concatenates the items in two lists C. converts the items in another object to a list D. calls a function that returns an aggregate value

B. the functions that were called prior to the exception

The stack is available when an exception occurs. It displays a list of A. the functions that have been called since the IDLE shell started B. the functions that were called prior to the exception C. all the local variables used by the program and their values D. all the local and global variables used by the program and their values

C. code the name of the argument, the assignment operator (=), and the default value

To assign a default value to an argument when you define a function you A. code the default value instead of its name in the arguments list B. set the default value for the argument in the first line of code inside the function C. code the name of the argument, the assignment operator (=), and the default value D. code the name of the argument, the default operator(:), and the default value

B. lower() method to convert all characters in each string to lowercase

To compare two strings with mixed uppercase and lowercase letters, a programmer can first use the A. upper() method to convert the first character in each string to uppercase. B. lower() method to convert all characters in each string to lowercase. C. lower() method to convert all characters after the first character in each string to lowercase. D. upper() method to convert all characters after the first character in each string to uppercase.

A. IDLE's editor

To create a Python program, you use A. IDLE's editor B. IDLE's interactive shell C. the command line

C. break statement

To jump to the end of the current loop, you can use the A. end statement B. continue statement C. break statement D. switch statement

B. IDLE's interactive shell

To test a Python statement, you use A. IDLE's editor B. IDLE's interactive shell C. the command time

C. 12, 12

What are the values of x and y in the add() function? A. 4, 3 B. 5,6 C. 12, 12 D. these variables don't exist

D. "My student ID is " + str(123456)

What is the argument of the print() function in the following Python statement? A. 123456 B. str(123456) C. "My student ID is" D. "My student ID is " + str(123456)

D. "My student ID is" + str(123456)

What is the argument of the print() function in the following Python statement? A. 123456 B. str(123456) C. "My student ID is" D. "My student ID is" + str(123456)

C. 114

What is the result of the following code? evenlist = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20] sum (evenlist, 4) A. 90 B. 20 C. 114 D. 30

B. 6.5

What is the value of my_num after the following statements execute? A. 0.5 B. 6.5 C. 6 D. 12.5

B. 35

What is the value of the total variable after the following code executes? A. 0 B. 35 C. 8 D. 45

B. line 1, syntax error

What line number of the following code contains an error and what type of error is it? A. line 1, runtime error B. line 1, syntax error C. line 3, runtime error D. line 8, logic error

C. line 4, runtime error

What line number of the following code contains an error and what type of error is it? A. line 2, syntax error B. line 3, syntax error C. line 4, runtime error D. line 5, logic error

C. Boolean

What type of expression has a value of either true or false? A. relational B. binary C. Boolean D. if-else

C. nothing will display

What will be displayed after the following code executes? A. Too low B. Too high C. nothing will display

C. error: you cannot use the += operator to add a string variable to an int value

What will be the result of the following code if the user enters 81 at the prompt? A. 88 will be displayed on the console B. 81 will be displayed on the console C. error: you cannot use the += operator to add a string variable to an int value D. error: you cannot print a numeric variable

C. error: you cannot use the +=operator to add a string variable to an int value

What will be the result of the following code if the user enters 81 at the prompt? A. 88 will be displayed on the console B. 81 will be displayed on the console C. error: you cannot use the +=operator to add a string variable to an int value D. error: you cannot print a numeric variable

D. Welcome! Now that you have learned about input and output, you may be wondering, "What is next?"

What will display after the following print() function is executed?

A. lions & tigers & bears oh, my!!

What will the following print() function display? A. lions & tigers & bears oh, my!! B. lions&tigers&bearsoh, my!! C. lions & tigers & bears & oh, my!! D. lions, & tigers, & bears, oh my!!

A. ghost witch ogre

What would be displayed after the following code executes? A. ghost witch ogre B. ghost, witch, ogre C. "ghost" "witch" "elf" "ogre" D. "ghost", "witch", "elf", "ogre"

D. nothing is wrong with this code

What, if anything, is wrong with this code? A. cannot mix camel case notation with underscore notation B. cannot change my_age to an int C. commas are used in the print() function that should be + D. nothing is wrong with this code

B. a string variable is used in an arithmetic expression

What, if anything, is wrong with this code? A. nothing is wrong with this code B. a string variable is used in an arithmetic expression C. the coding in the print() function contains illegal plus signs D. the input() function should be an int() function

C. an undeclared variable name is used in the print() function

What, if anything, is wrong with this code? A. nothing is wrong with this code B. the scores variable isn't converted to a string before printing. C. an undeclared variable name is used in the print() function D. the input() function is chained with the int() function

A. nothing is wrong with this code

What, if anything, is wrong with this code? A. nothing is wrong with this code B. the total variable isn't converted to a string before printing C. an undeclared variable name is used in the print() function D. the input() function is chained with the float() function

C. The program crashes and an error message is displayed

When an exception occurs while a program is running A. the program crashes B. an error message is displayed on the console C. the program crashes and an error message is displayed D. an error message is displayed but the program continues

D. view the values of all the variables that you've stepped through

When the IDLE debugger reaches a breakpoint, you can do all but one of the following. Which one is it? A. step through the program one statement at a time B. run the program until the next breakpoint is reached C. view the values of the local variables that are in scope D. view the values of all the variables that you've stepped through

C. display the values of the global constants used by the function

When you trace the execution of a program, you insert print() functions at key points in the program. It makes sense for these functions to do all but one of the following. Which one is it? A. display the name of the function that the print() function is in B. display the values of the local variables in the function C. display the values of the global constants used by the function D. display the values of the global variables used by the function

C. change line 8 to: average_cost = round(item_total / count - 1))

Which line should be changed to fix this logic error? A. change line 4 to: white count <= 4: B. change line 6 to: item_total += item -1 C. change line 8 to: average_cost = round(item_total / count - 1)) D. change line 1 to: count = 0

C. a while statement

Which of the following begins by testing a condition defined by a Boolean expression and then executes a block of statements if the condition is true? A. a for statement B. a switch statement C. a while statement D. a continue statement

B. flag = True

Which of the following creates a Boolean variable? A. flag = True or False B. flag = True C. if flag == True : D. flag == "False"

D. float

Which of the following data types would you use to store the number 25.62? A. str B. int C. num D. float

A. age >= 65

Which of the following in this expression is evaluated first A. age >= 65 B. age <= 18 C. status == "retired" D. age <= 65 or age <= 18

C. invalid variable names

Which of the following is not a common type of syntax error? A. forgetting a colon B. forgetting to close a parentheses C. invalid variable names D. improper indentation

D. nest an else clause within an elif clause

Which of the following is not an acceptable way to code a nested structure? A. nest a for loop inside a while loop B. nest an if statement inside a for loop C. nest a while loop inside an elif clause D. nest an else clause within an elif clause

B. deep copy of a list, both variables refer to the same list

Which of the following statements about list copies is not true? When you make a A. deep copy of a list, both variables refer to their own copy of the list B. deep copy of a list, both variables refer to the same list C. shallow copy of a list, both variables refer to the same list D. shallow copy of a list, the list is immutable

D. print(f"Subtotal: {subtotal}\n" f"Tax:" {tax}\n" f"Total: {total}")

Which of the following statements does not use implicit continuation?

C. the Python virtual machine

Which of the following translates bytecode into instructions for the computer? A. the IDE B. the Python interpreter C. the Python virtual machine D. the computer's operating system

B. firstName

Which of the following variable names uses camel case? A. first_name B. firstName C. pay_rate D. prate

A. fruit.remove("mangos") or fruit.pop(3)

Which of these methods would you use to remove the item "mangos" from the following list? fruit = ["apple, "banana", "grapes", "mangos", "oranges"] A. fruit.remove("mangos") or fruit.pop(3) B. fruit.remove(3) or fruit.pop("mangos") C. fruit = remove("mangos") or fruit = pop(3) D. fruit = pop("mangos")

B. syntax

Which type of error prevents a program from compiling and running? A. exceptional B. syntax C. runtime D. logic

A. syntax errors

Which type of errors must be fixed before the program can be compiled? A. syntax errors B. logical errors C. violations D. exceptions


Ensembles d'études connexes

MGT 375 - Midterm Exam 2 (7, 8, 13, 15)

View Set

CH.1 - LIMITS, ALTERNATIVES, CHOICES

View Set

Medical Terminology Chapter 6 Learning Activity 6-6

View Set

Middle Ages Quiz 1: Feudalism, The Church, and Medieval Life

View Set

Accounting Chapter 17 Learnsmart/Homework

View Set

DSM-5 Study Guide Questions and Answers

View Set

Unit 4 English Which sentence uses numbers correctly?

View Set