Programming Final

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

The _______________ statement is used to create a decision structure.

if

Benefits of using Functions

- simpler code - code reuse - better testing and debugging - faster development - easier facilitation of teamwork

Where does a computer store a program and the data that the program is working with while the program is running? A. Main memory B. CPU C. secondary storage D. microprocessor

A. main memory

Which of the following statements takes the value from a variable (your_number) and stores it in another variable (my_number)? A. my_number = your_number B. my_number == your_number C. your_number == my_number D. your_number = my_number

A. my_number = your_number

Which step creates a connection between a file and a program? A. open the file B. read the file C. process the file D. close the file

A. open the file

When using the __________ operator, one or both subexpressions must be true for the compound expression to be true. A. or B. and C. not D. maybe

A. or

Which command stores a string in memory? A. x = input("Enter an integer") B. y = int(x) C. print(" You entered" ,x) D. print("You entered", y)

A. x = input("Enter an integer")

Which of the following may be used as variable names in Python? A.totalgrade B. 133t C. 4thQuarterINcome D. all of these

A.totalgrade

What type of volatile memory is usually used only for temporary storage while running a program? A. ROM B. TMM C. RAM D. TVM

C. RAM

Which statement can be used to handle some of the runtime errors in a program? A. an exception statement B. a try statement C. a try/except statement D. an exception handler statement

C. a try/except statement

Multiple Boolean expressions can be combined by using a logical operator to create _____ expressions. A. sequential B. logical C. compound D. mathematical

C. compound

_______________ access is when you can jump to any piece of data in the file. A. Sequential B. Random C. Number D. Direct

D. Direct

What is the output of the following print 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.

D. The path is D:\sample\test.

The line continuation character is a ____________. A. # B. % C. & D.\

D. \

A(n) _______________ operator determines whether a specific relationship exists between two values.

relational

A(n) _____________ decision structure provides only one alternative path of execution

single alternative

How many times will "hello world" be printed in the following program? count = 12 while count >= 1: print("hello world") count = 2

6

Which mode specifier will erase the contents of a file if it already exists and create it if it does not exist? A. 'w' B. 'r' C. 'a' D. 'e'

A. 'w'

What is the largest value that can be stored in one byte? A. 255 B. 128 C. 8 D. 65535

A. 255

What is the result when Python evaluates the following expression? 100 / 2**2 / 5 A. 5.0 B. 20.0 C. 20 D. 5

A. 5.0

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

A. executed

What is a group of statements that exists within a program for the purpose of performing a specific task? A. function B. subtask C. process D. subprocess

A. function

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

A. header

Which of the following is the correct if clause to use to determine whether choice is other than 10? A. if choice != 10: B. if choice != 10 C. if choice <> 10: D. if choice <> 10

A. if choice != 10:

The ________ 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. string_input

A. input

The ________ built- in function is used to read a number that has been typed on the keyboard. A. input() B. read() C. get() D. keyboard()

A. input()

What is the output of the following print 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'

C. I'm ready to begin

The decision structure that has two possible paths of execution is known as __________. A. single alternative B. double alternative C. dual alternative D. two alternative

C. dual alternative

What is the error in the following code? numberOfPies = 3 if numberOfPies - eatenPies > 25: print("Wow, it's full of pies") A. numberOfPies is the wrong data type B. eatenPies is the wrong data type C. eatenPies has not been defined before using it D. print requires 2 arguments, not 1

C. eatenPies has not been defined before using it

The process known as the _______ cycle is used by the CPU to execute instructions in a program. A. decode- fetch- execute B. decode- execute- fetch C. fetch- decode- execute D. fetch- execute- decode

C. fetch- decode- execute

Which of the following is the correct if clause to determine whether y is in the range 10 through 50? 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

C. if y > 10 and y < 50

Which is the correct way to open a file named 'users.txt' in 'r' mode? A. infile = open('r', users.txt) B. infile = read('users.txt', 'r') C. infile = open('users.txt', 'r') D. infile = readlines('users.txt', r)

C. infile = open('users.txt', 'r')

Which of these is not a major component of a typical computer system? A. central processing unit B. main memory C. operating system D. secondary storage devices

C. operating systems

Which is the correct way to open a file named 'users.txt' to write to it? A. outfile = open('w', users.txt) B. outfile = write('users.txt', 'w') C. outfile = open('users.txt', 'w') D. outfile = open('users.txt')

C. outfile = open('users.txt', 'w')

Which symbol is used to mark the beginning and end of a string? A. slash B. asterick C. quotation D. comma

C. quotation

Which of the following represents an example to calculate the sum of numbers (accumulator)? A. total + number = total B. number += number C. total += number D. total + number

C. total += number

What are the values that the variable 'num' contains through the iterations of the following 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,3

D. 0,1,2,3

What is not an example of an augmented assignment operator? A.*= B. /+ C. -= D. <=

D. <=

How would you write 'Mary Smith' to the customer file? A. customer file.write('Mary Smith') B. customer.write('w' , 'Mary Smith') C. customer.input('Mary Smith') D. customer.write('Mary Smith')

D. customer.write('Mary Smith')

A ___________________ variable is created inside a function. A. global B. constant C. named constant D. local

D. local

What is the output? def pass_it(x ,y): z = x, ',' , y num1 = 4 num2 = 8 answer = pass_it(num1 , num2) print(answer) A. 4,8 B. 8,4 C. 48 D. none

D. none

In a value returning function, the value of the expression that follows the keyword ___________ will be sent back to the part of the program that called the function. A. def B.. result C. sent D. return

D. return

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

D. scope

A(n) _____________ access file is also known as a direct access file. A. sequential B. random C. numbered D. text

D. text

Python provides a special version of a decision structure known as the _________________ statement, which makes the logic of the nested decision structure simper to write.

if- elif- else

A(n) ______________ statement will execute one block of statements if its condition is true, or another block if its condition is false.

if- else

Show what will be printed out. j = 1 while j <= 4: print(j) j = j + 1

1 2 3 4

How many times will the value of i be printed out? i = 0 while i < 10: print(i) i = i +1 print(i)

11

Which mode specifier will open a file but will not let you change the file or write to it? A. 'w' B. 'r' C. 'a' D. 'e'

B. 'r'

Which mathematical operator is used to raise five to the second power in Python? A. / B.** C. ^ D. ~

B. **

Which is the concatenate operator? A. * B. + C. % D. Concat

B. +

What is the output? def main(): print("The answer is", magic(5)) def magic(num): answer = num + 2 * 10 return answer main() A. 70 B. 25 C. 100 D. The statement will cause a syntax error

B. 25

What is the output? def pass_it(x,y): z = y**x return (z) num1 = 3 num2 = 4 answer = pass_it( num1, num2) print(answer) A. 81 B. 64 C. 12 D. None

B. 64

When using the ________ operator, both subexpressions must be true for the compound expression to be true. A. or B. and C. not D. maybe

B. and

A(n) ____________ is any piece of data that is passed into a function when function is called. A. global variable B. argument C. local variable D. parameter

B. argument

A(n) _______ structure is a logical design that controls the order in which a set of statements executes. A. function B. control C. sequence D. iteration

B. control

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 A. true B. false C. 8 D. 5

B. false

After the execution of the following statement, the variable sold will reference the numeric literal value as a(n) _____ data type: sold = 256.752 A. int B. float C. str D. currency

B. float

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

B. import random

Which of the following will assign a random integer in the range of 1 through 50 to the variable number? A. random(1,50) = number B. number = random.randint(1,50) C. randint(1,50) = number D. number = random(range(1,50))

B. number = random.randint(1,50)

Which method could be used to strip specific characters from the end of a string? A. estrip B. rstrip C. strip D. remove

B. rstrip

A Boolean variable can reference on of two values A. yes or no B. true or false C. T or F D. Y or N

B. true or false

What is the format for the while clause in Python? A. while condition B. while condition: C. while condition statement D. while condition: statement

B. while condition:

A value- returning function is A. a single statement that performs a specific task B. called when you want the function to stop C. a function that will return a value back to the part of the program that called it D. function that receives a value when called

C.

If value1 is 2.0 and value2 is 12, what is the output of the following command? print(value1 * value2) A. 24 B. value1 * value2 C. 24.0 D. 2.0 * 12

C. 24.0

How many iterations will the for loop perform? for x in range (2, 11, 2) A. 3 B. 4 C. 5 D. it will keep running until user kills the program

C. 5

What is the result when Python evaluates the following expression? 4 + 9 // 2 A. 11 B. 8.5 C. 8 D. 3

C. 8


Kaugnay na mga set ng pag-aaral

Intro to Networking Chapter 9: Wide Area Networking

View Set

Using Python to Interact with the Operating System

View Set

SPCH-1321 2807 1 CHAPTER 6 OVERLOOK

View Set