Computer Science Exam 2

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

import math

to use math functions what do you first have to do?

import math

to use random functions what do you first have to write?

total += number

total = total + number could be rewritten as what?

condition-controlled loop

uses a true/false condition to control the number of times that it repeats (while)

The first item is retrieved before the loop starts.

what is a priming read?

15

what will the following code display? total = 0 for count in range(1, 6): total = total + count print(total)

local

A _____ variable is created inside a function and cannot be accessed by statements that are outside the function.

function

A ______ is a group of statements that exist within a program for the purpose of performing a specific task.

parameter

A ______ is a variable that receives an argument that is passed into a function.

block

A ______ is simply a set of statements that belong together as a group. These statements are performed any time the function is executed.

global

A _______ variable is accessible to all the functions in a program file.

heiarchy chart

A _________, which is also known as a structure chart, shows boxes that represent each function in a program

hierarchy chart

A __________ is a diagram that gives a visual representation of the relationships between functions in a program. flowchart function relationship chart symbol chart hierarchy chart

local variable

A __________ is a variable that is created inside a function. global variable local variable hidden variable none of the above; you cannot create a variable inside a function

sentinel

A ____________ is a special value that marks the end of a sequence of values.

divide and conquer

A design technique that helps to reduce the duplication of code within a program and is a benefit of using functions is __________. code reuse divide and conquer debugging facilitation of teamwork

top-down design

A design technique that programmers use to break down an algorithm into functions is known as __________. top-down design code simplification code refactoring hierarchical subtasking

header and body

A function definition has what two parts?

function

A group of statements that exist within a program for the purpose of performing a specific task is a(n) __________. block parameter function expression

nested loop

A loop that is inside another loop is called a ________

A

A set of statements that belong together as a group and contribute to the function definition is known as A)block B)parameter C)header D)return

return

A value-returning function has a _______ statement that returns a value back to the part of the program that called it

global variable

A variable that is visible to every function in a program file is a __________. local variable universal variable program-wide variable global variable

D

A variable used to keep a running total is called a(n) A)total B)summer C)running total D)accumulator

scope

A variable's ______ is the part of a program in which the variable may be accessed.

A

A(n) ________ chart is also known as a structured chart. A)hierarchy B)data C)organizational D)flow

C

A(n) ________ is a variable that receives an argument that is passed into a function. A)named constant B)argument C)parameter D)global variable

C

A(n) ________ structure is a structure that causes a statement or a set of statements to execute repeatedly. A)module B)sequence C)repetition D)decision

sentinel

A(n) _________ is a special value that signals when there are no more items from a list of items to be processed. This value cannot be mistaken as an item from the list. sentinel flag signal accumulator

infinite

A(n) _________ loop has no way of ending and repeats until the program is interrupted. indeterminate interminable infinite timeless

accumulator

A(n) _________ variable keeps a running total. sentinel sum total accumulator

argument

A(n) __________ is a piece of data that is sent into a function. argument parameter header packet

scope

A(n) __________ is the part of a program in which a variable may be accessed. declaration space area of visibility scope mode

True

Both 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 False

before

Does the while loop test its condition before or after it performs an iteration?

iteration

Each repetition of a loop is known as a(n) _________ . cycle revolution orbit iteration

Garbage in, garbage out

GIGO means what?

none

How many times will 'Hello World' be printed in the following program? count = 10 while count < 1: print('Hello World')

infinite loop

an _________ continues to repeat until the program is interrupted

days_left -= 5

Rewrite: days_left = days_left − 5

price *= 10

Rewrite: price = price * 10

price /= 2

Rewrite: price = price / 2

quantity += 1

Rewrite: quantity = quantity + 1

F

T or F: A condition-controlled loop always repeats a specific number of times.

T

T or F: A function in Python can return more than one value.

T

T or F: A hierarchy chart does not show the steps that are taken inside a function.

T

T or F: Different functions can have local variables with the same names because the functions cannot see each other's local variables.

T

T or F: Python allows you to pass multiple arguments to a function.

T

T or F: The while loop is a pretest loop.

F

T or F: To calculate the total number of iterations of a nested loop, add the number of iterations of all the loops.

augmented assignment

The -= operator is an example of a(n) _________ operator. relational augmented assignment complex assignment reverse assignment

A

The Python library functions that are built into the Python ________ can be used by simply calling the required function. A)interpreter B)code C)compiler D)linker

seed

The ______ value is used in the calculation that returns the next random number in the series.

C

The ________ of a local variable is the function in which that variable is created. A)space B)global reach C)scope D)definition

pass

The _____________ keyword is ignored by the Python interpreter and can be used as a placeholder for code that will be written later. placeholder pass pause skip

A

The first line in a function definition is known as the function A)header B)block C)parameter D)return

header

The first line is known as the function _________. It marks the beginning of the function definition

header

The first line of a function definition is known as the __________. body introduction initialization header

priming read

The input operation that appears just before a validation loop is known as the _________ . prevalidation read primordial read initialization read priming read

True

The 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 False

seed

The random module uses the ______ value as a base to generate a random number.

True

The randrange function returns a randomly selected value from a specific sequence of numbers. True False

iterable

The range function creates a type of object known as an _________. An _________ is an object that is similar to a list. It contains a sequence of values that can be iterated over with something like a loop.

accumulator

The variable used to keep the running total is called an ____________.

pretest

The while loop is a _________ type of loop. pretest no-test prequalified post-iterative

error traps

Validation loops are also known as _________ . error traps doomsday loops error avoidance loops defensive loops

A

What 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, 4, 6, 8 B)2, 3, 4, 5, 6, 7, 8, 9 C)2, 5, 8 D)1, 3, 5, 7, 9

A

What does the following statement mean? num1, num2 = get_num() A)The function get_num() is expected to return a value for num1 and for num2. B)This statement will cause a syntax error. C)The function get_num() is expected to return one value and assign it to num1 and num2. D)The function get_num() will receive the values stored in num1 and num2.

A

What type of function can be used to determine whether a number is even or odd? A)Boolean B)math C)odd D)even

******

What will the following code display? for col in range(6): print('*', end='')

0 100 200 300 400 500

What will the following code display? for number in range(0, 501, 100): print(number)

10 9 8 7 6

What will the following code display? for number in range(10, 5, −1): print(number)

2 3 4 5

What will the following code display? for number in range(2, 6): print(number)

5 4 3 2 1

What will the following code print? for num in range(5, 0, −1): print(num)

B

When a function is called by its name during the execution of a program, then it is A)exported B)executed C)defined D)located

global

When possible, you should avoid using __________ variables in a program. local global reference parameter

value-returning function

When you call a _________ function, it executes the statements that it contains, then returns a value back to the statement that called it.

void

When you call a _________ function, it simply executes the statements it contains and then terminates.

B

Which of the following functions returns the largest integer that is less than or equal to its argument? A)lesser B)floor C)greater D)ceil

C

Which of the following is not an augmented assignment operator? A)*= B)/= C)<= D)+=

A

Which of the following statements causes the interpreter to load the contents of the random module into memory? A)import random B)download random C)load random D)upload random

call

You __________ a function to execute it. define call import export

B

________ 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)Data validation B)Input validation C)Correcting data D)Correcting input

structure chart

a heiarchy chart is also know as a ______

count-based loop

repeats specific number of times (for)

pretest

a while loop is known as a ______loop

argument

An ______ is any piece of data that is passed into a function when the function is called.

error trap

An input validation loop is sometimes called an ________.

True

In Python you can have a list of variables on the left side of the argument operator. True False

top-down

Programmers commonly use a technique known as ________ design to break down an algorithm into functions.

IPO chart

This is a design tool that describes the input, processing, and output of a function. hierarchy chart IPO chart datagram chart data processing chart

library function

This is a prewritten function that is built into a programming language. standard function library function custom function cafeteria function

random

This standard library function returns a random floating-point number in the range of 0.0 up to 1.0 (but not including 1.0). random randint random_integer uniform

uniform

This standard library function returns a random floating-point number within a specified range of values. random randint random_integer uniform

randit

This standard library function returns a random integer within a specified range of values. random randint random_integer uniform

return

This statement causes a function to end and sends a value back to the part of the program that called the function. end send exit return

Boolean

This type of function returns either True or False. Binary true_false Boolean logical

definition

To create a function, you write its _________

call

To execute a function, you must ______ it.

False

To 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 False


Set pelajaran terkait

CNA 170 | Ch 9, Design for Wireless Networking

View Set

Automated and Emerging Technologies : Artificial Intelligence

View Set

Pathophysiology - Genetics and Disease

View Set

Chapter 16: Control Systems and Quality Management

View Set

বাংলাদেশের অবস্থান ও সীমানা

View Set

Legal/Illegal Interview Questions

View Set