CMPS 152 TEST 1

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

Which of the following symbols can be used as part of an identifier? Select one: a. $ b. @ c. & d. _ (underscore)

d. _ (underscore)

Which function can be used to concatenate and print objects in R? Select one: a. fprintf() b. concat() c. print() d. cat()

d. cat()

Which method call returns the number of elements in my_list? Select one: a. my_list.count() b. size(my_list) c. my_list.size() d. len(my_list)

d. len(my_list)

A _____ is a named item used to hold a value. Select one: a. constant b. number c. statement d. variable

d. variable

What is the value of x after the following code is executed? x = 15 x = x + 1 x = x * 2 x = 30 - x Answer:

-2

Consider the following program: t = 15 t = t * 2 t = t + 1 t = t - 4 put t What does the program produce as output? Answer:

27

What is the value of 11 // 2? Answer:

5

Which symbol represents the multiplication operation in programming? a. * b. () c. x d. .

a. *

What is the value of x after the following code is executed? x = 17 if x * 2 <= 34: x = 0 else: x = x + 1 x = x + 1 Select one: a. 1 b. 18 c. 19 d. 35

a. 1

What is the value of y after the following code is executed? Note that the question asks for y, not x. x = 10 y = x + 2 x = 12 Select one: a. 12 b. 8 c. 14

a. 12

What is the value of test_val after the following code is executed? a = 12 test_val = 6 if a * 2 == test_val: a = a + 7 else: test_val = 2 * a test_val = a + 1 Select one: a. 13 b. 7 c. 24 d. 25

a. 13

What is the value of grade after the following code is executed? grade = 70 if (x > 70) { bonus_points = 2 grade = grade + bonus_points } cat("Your Grade is", grade) Select one: a. 70 b. 71 c. 68 d. 72

a. 70

What are the contents of names_list after the following code is executed? names_list = ['one', 'two', 'three'] digits_list = ['1', '2', '3'] names_list = names_list + digits_list Select one: a. ['one', 'two', 'three', '1', '2', '3'] b. ['1one', '2two', '3three'] c. ['two', 'four', 'six'] d. ['1', '2', '3', 'one', 'two', 'three']

a. ['one', 'two', 'three', '1', '2', '3']

A sequence of instructions that solves a problem is called _____. Select one: a. an algorithm b. a process c. an allegory d. turtle graphics

a. an algorithm

Which of the following identifiers is valid? Select one: a. max_age b. 32area c. transfer$ d. True

a. max_age

In Python, which of the following assignment statements creates a list with 4 integer elements? Select one: a. my_list = [7, 2, -8, 16] b. my_list = [4] c. my_list = ['1', '2', '3', '4'] d. my_list = integer(4)

a. my_list = [7, 2, -8, 16]

Which of the following refers to the first element of my_list in R? Select one: a. my_list[[1]] b. my_list(1) c. my_list[[0]]

a. my_list[[1]]

Which statement outputs the text: "I won't quit!"? Select one: a. print("I won't quit!") b. print(I won't quit!) c. print('I won't quit!', punctuation=True) d. print('I won't quit!")

a. print("I won't quit!")

Which print statement displays the value of a variable called argv in a module called sys? Select one: a. print(sys.argv) b. print(argv in sys) c. print(module sys var argv) d. print(sys_argv)

a. print(sys.argv)

Which statement reads a user-entered string into variable user_name? Select one: a. user_name = input() b. input = user_name() c. user_name = "input()" d. input() => user_name

a. user_name = input()

Which expression using parentheses is equivalent to the following expression: x - y * -z / 3 Select one: a. x - ((y * (-z)) / 3) b. (x - y) * ((-z) / 3)) c. x - (y * ((-z) / 3)) d. (x - (y * (-z))) / 3

a. x - ((y * (-z)) / 3)

Which symbol is used in Python to create a comment? Select one: a. // b. # c. * d. C

b. #

15 _____ 3 = 0 Select one: a. * b. % c. // d. /

b. %

In Python, if text_line = 'one fish two fish', what is the value of text_line[6]? a. 'h' b. 's' c. ' ' d. 'i'

b. 's'

Which code example is an expression? Select one: a. # Display x b. (x * y ) /2 c. x=4 d. print(x)

b. (x * y ) /2

What is the ending value of z? x = 0.3 z = math.pow(math.ceil(x), 2) Select one: a. 0.09 b. 1.0 c. 1.09 d. 0.0

b. 1.0

Which of the following syntax can be used to assign 2 to the variable x in R? Select all that apply. Select one or more: a. -< b. = c. <- d. :=

b. = c. <-

Which statement correctly explains a difference between lists and tuples? Select one: a. List items use [ ] operators to access items by index, while tuples use operators to access items by index. b. List items can be changed, while tuple items can't be changed. c. The built-in function len() works with lists but not with tuples. d. List items can be of any type, while tuple types can only be numbers.

b. List items can be changed, while tuple items can't be changed.

In Python, which of the following statements about my_list is false? my_list = ['JFK', 'LAX', 'MIA'] Select one: a. The index of the last item in the list is 2 b. The element at index 1 is 'JFK' c. The list has a length of 3 d. The list elements are all strings

b. The element at index 1 is 'JFK'

Which of the following data values is best represented with a floating point variable? Select one: a. The number of pets in a house. b. The speed of a snail. c. The number of children in a classroom. d. The number of acorns in a tree.

b. The speed of a snail.

Which of the following statements has a syntax error? Assume age and years are variables that have already been defined. Select one: a. age = -15 b. age + 2 = years c. age = years - 2 d. age = 17 - 2

b. age + 2 = years

A language is called _____ when upper case letters in identifiers are considered different from lower case letters. a. case strict b. case sensitive c. unambiguous d. camel case

b. case sensitive

Assume a and b are variables that hold the base and height of a right triangle. The length of the long side (hypotenuse) is calculated as the square root of a^2 + b^2. Which expression calculates the length of the hypotenuse? Select one: a. math.sqrt(math.pow(a * a), math.pow(b * b)) b. math.sqrt(math.pow(a, 2)) + math.pow(b, 2))) c. math.square_root(a * a + b * b) d. math.pow(math.sqrt(a), 2) + math.pow(math.sqrt(b), 2)

b. math.sqrt(math.pow(a, 2)) + math.pow(b, 2)))

Which of the following creates a list in R? Select one: a. my_list = (1, 2, 3) b. my_list <- list(1, 2, 3) c. my_list <- list[1, 2, 3] d. my_list <- (1, 2, 3)

b. my_list <- list(1, 2, 3)

Which statement removes the last element of my_list? Select one: a. my_list.remove(len(my_list)) b. my_list.pop(len(my_list)-1) c. my_list.pop(len(my_list) d. my_list.remove(len(my_list)-1)

b. my_list.pop(len(my_list)-1)

Basic instruction types are input, process, and _____. a. calculation b. output c. memory d. assignment

b. output

Assigning a value to a floating point variable that is too large for the computer to represent is a condition called _____ . Select one: a. bit error b. overflow c. system error d. overcapacity

b. overflow

Which statement does not print a newline character at the end? Select one: a. print('First part...\n') b. print('First part...', end='') c. print('First part...') d. print('First part...', end="-\n")

b. print('First part...', end='')

In the statement:age = input('Enter your age: '), the string 'Enter your age: ' is called a _____. a. variable b. prompt c. assignment d. prefix

b. prompt

Dividing by zero is an example of which type of error? Select one: a. logic b. runtime c. syntax d. infinity

b. runtime

Which of the following can be used to determine the type of an object in R? Select one: a. var() b. typeof() c. type() d. float()

b. typeof()

Space, tab, and newline are all called _____ characters. Select one: a. symbol b. whitespace c. noprint d. space-line

b. whitespace

Which statement is equivalent to the following assignment? x -= 2 + y Select one: a. x = x - 2 + y b. x = x - (2 + y) c. x = 2 + y - x d. x = -(2 + y)

b. x = x - (2 + y)

Which symbol is used for creating comments in R? Select one: a. // b. % c. # d. &

c. #

In R, if text_line = 'one fish two fish', what is the value of substr(text_line,6,6)? a. 's' b. 'i' c. ' ' d. 'h'

c. ' '

In Python, what is the output? my_list = [2, 8, 3, 1, 18, 5] print(my_list[3] + my_list[1] * 2) Select one: a. 7 b. 18 c. 17 d. 10

c. 17

Which floating-point literal correctly represents the scientific notation value: 2.3 x 10^7? Select one: a. 2.3xe7 b. 2.3e10^7 c. 2.3e7 d. 2.3*10e7

c. 2.3e7

Which of the following is not a valid expression? Assume x and y are integer variables. Select one: a. y / x * 2 b. (x - 3*y) c. 2x + 3y d. x / (y * 7)

c. 2x + 3y

What is the value of x after the following code is executed? x = 7 If x < 7 x = x + 1 x = x + 2 Select one: a. 8 b. 10 c. 9 d. 7

c. 9

_____ is the process where objects that are no longer needed are deleted. Select one: a. Object recycling b. Identity recycling c. Garbage collection d. Memory clearing

c. Garbage collection

Which branch structure does a program use to output "Yes" if a variable's value is positive, or "No" otherwise? Select one: a. if b. else c. if-else

c. if-else

Which statement makes the code in the math module available? Select one: a. include math b. allow math c. import math d. use math

c. import math

Which function converts a string to an integer? Select one: a. convert(string, int) b. integer() c. int() d. string_to_int()

c. int()

Which instruction displays variables or expression values in Python? Select one: a. put() b. display() c. print() d. output()

c. print()

Which expression gives the number of whole minutes that corresponds to some number of seconds? Select one: a. seconds % 60 b. seconds / 60 c. seconds // 60 d. seconds * 60

c. seconds // 60

n an instruction like: z = x + y, the symbols x, y, and z are examples of _____. Select one: a. instructions b. output c. variables d. visibles

c. variables

Which statement has a syntax error? Assume variables x, y, z, and age have already been defined. Select one: a. y = y b. print('Name, age') c. x + y = z d. age = '32'

c. x + y = z

With the logic block shown below, what is output when grade is assigned with the value 75? If grade < 50 Put "F" to output Else If grade < 60 Put "D" to output Else If grade < 75 Put "C" to output Else If grade < 85 Put "B" to output Else If grade <= 100 Put "A" to output ElsePut "Invalid grade" to output Select one: a. Invalid Grade b. A c. B d. C

c.B

15 _____ 3 = 5.0 Select one: a. % b. ^ c. // d. /

d. /

What is the value of x after the following code is executed? x <- 17 if (x * 2 <= 12) { x = 0 } else { x = x + 2 } x = x + 1 Select one: a. 19 b. 1 c. 0 d. 20

d. 20


Ensembles d'études connexes

Chapter 19 "GDP: Measuring Total Production and Income

View Set

Princeton Review Exams: Psych/Sociology

View Set

IL Life - Provisions, Riders and Options combined sets

View Set

Focus on Vocabulary - Why are you happy?

View Set