programming exam

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

hot_plate = True if hot_plate: print("Be careful, hot plate!") else: print("The plate is ready.") What is the output from running the above code. A. "Be careful, hot plate!" B. "The plate is ready." C. "True" D. "False"

A. "Be careful, hot plate!"

x = 0 while True: if x < 10: print('run forever') x += 1 else: break What is the output from running the above code most like? A. "run forever" (10 times) B. "run forever" (9 times) C. "run forever" D. No output

A. "run forever" (10 times)

Which function displays a datetime.date object in the form Monday, January 01, 2018? A. .strftime("%A, %B %d, %Y") B. .strftime("%A, %M %D, %Y") C. .strftime("%A, %M %d, %Y") D. .strftime("%A, %M %D, %Y")

A. .strftime("%A, %B %d, %Y")

Given the following inputs for the composition of students in a class: Girls = 12 Boys = 20 African American = 25% of the class Caucasian = 75% of the class According to Boolean Logic, what number of students is returned with the statement "Total number of students that are girls and African American Boys?" A. 0 B. 17 C. 32 D. 8

A. 0

Which of the following statements about tuples is true? A. A tuple can contain list elements. B. A tuple cannot contain another tuple. C. After you define a tuple, you can add elements to it. D. You define the elements of a tuple within the square brackets.

A. A tuple can contain list elements.

In Python, what is the base class for all built-in exceptions? A. BaseException B. Error C. Exception D. IOError

A. BaseException

Which two statements about the pydoc module are true? A. It generates documentation from the docstrings in a module. B. It generates documentation for a module without importing it. C. It imports a module and then generates documentation for the module. D. it automatically suppresses module functions from running while generating documentation for the module.

A. It generates documentation from the docstrings in a module. C. It imports a module and then generates documentation for the module.

Which information should you include in a multi-line docstring for a function? A. arguments, return values, and exceptions B. function name C. function parameters D. public methods and instance variables

A. arguments, return values, and exceptions

What does type(3.55) return? A. float B. int C. str D. all of the above

A. float

Which three data types can you use for dictionary keys? (Choose three.) A. float B. int C. lists D. other dictionaries E. string

A. float B. int E. string

Which statement best describes a String in Python/Computer Science? A. sequence of characters B. series of 1's and 0's C. computer keyboard D. object existing in four dimensions

A. sequence of characters

id = 3556 if id > 2999: print(id, "is a new student") else: print(id, "is an existing student") What is the output of the above line of code? A. "id, is a new student" B. "3556 is a new student" C. "id, is an existing student" D. "3556 is an existing student"

B. "3556 is a new student"

Which choice best represents the ouitput of the following code: student_name = "iteration" new_word = " " for letter in student_name[:3]: new_word += letter print(new_word) A. "ration" B. "ite" C. "iter" D. "ation"

B. "ite"

def add_numbers(num_1, num_2 = 10): return num_1 + num_2 Choose the correct output of calling the function above using the following code: print(add_numbers(100)) A. 100 B. 110 C. 200 D. An error

B. 110

Choose the best representation of the output expected for the following code: cities = ["New York", "Shanghai", , "Munich", "tokyo", "Dubai", "Mexico City", "Sao Paulo", "Hyderabad"] for city in cities: if city.startswith("P"): print (city) elif city.startswith("D"): print(city) A. Sao PauloDubai B. Dubai C. Sao Paulo D. None of the above

B. Dubai

Which statement about local variables is true? A. A local variable can be read from the global scope B. You can use the same variable name in multiple functions. C. A local variable in one function can be read from another function. D. A function can update a global variable in a local scope by using the same name for a local variable and assigning a new variable.

B. You can use the same variable name in multiple functions.

Choose the item that best completes the following sentence: "A Python list..." A. uses index 1 for the first item on the list. B. can contain both strings and numbers together as list items. C. can contain either all strings or all numbers as list items, but not together. D. cannot contain other Python lists.

B. can contain both strings and numbers together as list items.

Which code should you use to import a function named abc from a Python module named xyz? A. import abc B. from xyz import abc C. import abc from xyz D. import mod xyz fn abc

B. from xyz import abc

Which code overwrites (replaces) the "0" with a "5" in the following numbers list? numbers = [1, 1, 0] A. numbers[3] = 5 B. numbers[2] = 5 C. numbers.append(5) D. numbers.insert(2.5)

B. numbers[2] = 5

name = "Jin Xu" if type(name) == type("Hello"): print(name, "is a string entry") else: print(name, "is not a string entry") What is the output from running the above line of code? A. "Hello Jin Xu" B. "Jin Xu is not a string entry" C. "Jin Xu is a string entry" D. "string"

C. "Jin Xu is a string entry"

def low_case(words_in): return words_in.lower() Choose the correct output of calling the function above using the following code: words_lower = low_case("Return THIS lower") print(words_lower) A. "Return THIS lower" B. No Output C. "return this lower" D. An error

C. "return this lower"

calculation = 5 + 15 / 5 + 3 * 2 - 1 print(calculation) What is the best estimate for the output of the above code? A. 13 B. 9 C. 13.0 D. 9.0

C. 13.0

1. name = input("enter your name") 2. print(name, "your score is", score) 3. score = 199 Order the above-numbered code lines in the proper sequence. A. 1,2,3 B. 2,3,1 C. 3,1,2 D. 3,2,1

C. 3,1,2

When using Python, which mathematic operation returns a value of 2? A. 42 / 4 B. 42 // 4 C. 42 % 4 D. 42 ** 4

C. 42 % 4

When using Python, what is the result of the mathematic operation 1 ** (2 * 3) / 4 + 5? A. 0.11 B. 0.67 C. 5.25 D. 6.50

C. 5.25

PriNt ("Hello World!") will not output the message "Hello World!". What will it result in? A. TypeError B. SyntaxError C. NameError D. all of the above.

C. NameError

What does the Python code: score = 3 + "45" result in? A. 48 B. 345 C. TypeError D. type()

C. TypeError

Which is an example of the proper use of the Python input () function? A. answer = input(enter your answer:) B. answer = INPUT(enter your answer:) C. answer = input("enter your answer:") D. answer = INPUT("enter your answer:")

C. answer = input("enter your answer:")

Choose the item that best completes the sentence: "A Python list..." A. cannot be changed after initialization. B. can add items of the same type only. C. can add items to the end of the list using the .append() method. D. always appends to index 0 (zero).

C. can add items to the end of the list using the .append() method.

Which code is the best use of Python that deletes the "5" in the following numbers list? numbers = [7, 1, 5, 8, 0] A. numbers[3] = " " B. numbers[2].delete() C. del numbers[2] D. numbers remove(2)

C. del numbers[2]

Which is a properly formatted Python print () function example? A. print("Welcome the", 3, New students!) B. print("Welcome the", 3+ New students!) C. print("Welcome the", 3, "New students!") D. print("Welcome the", 3+ "New students!")

C. print("Welcome the", 3, "New students!")

Which Python code results in output of a sorted scores list with changing the original scores list below to be in a sort order? A. print(scores.reverse()) B. print(sorted(scores)) C. print(scores.sort()) D. All of the above.

C. print(scores.sort())

What does type("Hello World!") return? A. int B. float C. str D. all of the above

C. str

day = "monday" if day.capitalize() == "Monday": print("Start the week!") else: pass What is the output from running the above code? A. True B. False C. No Output D. "Start the week!"

D. "Start the week!"

size_num = "8 9 10" size = "8" # user input if size.isdigit() == False: print("Invalid: size should only use digits") elif int(size) < 8: print("size is too low") elif size in size_num: print("size is recorded") else: print("size is too high") What is the output from running the above code? A. "Invalid: size should only use digits" B. "size is too high" C. "size is too low" D. "size is recorded"

D. "size is recorded"

time = 3 while True: print('time is', time) if time == 3: time = 4 else: break What is the output from running the above code most like? A. "time is 3" B. "time is 4" C. no output D. "time is 3" & "time is 4"

D. "time is 3" & "time is 4"

Which code formats the string "Green" to "GREEN"? A. . isupper() B. . capitalize() C. . istitle() D. . upper()

D. . upper()

In an os function, which syntax can you use to move up one folder in the current directory structure? A. / B. \ C. \\ D. ..

D. ..

x = 3 y = 3 calculation = x/y print(calculation) What is the best estimate for the output of the above code? A. 9 B. 9.0 C. 1 D. 1.0

D. 1.0

Which of the following data/inputs Cannot be contained in a variable: A. String B. Integer C. Strings containing numbers D. All can be assigned to a variable

D. All can be assigned to a variable

name = "Tobias" print(name == "Alton") What is the output from running the above code? A. "Tobias = Alton" B. "Alton" C. True D. False

D. False

Which clause should you use for code that you want to execute regardless of whether an exception is raised? A. else B. elseif C. except D. finally

D. Finally

Which process can you use to assign the values of a tuple to multiple variables? A. Convert the tuple into a list B. Create a homogeneous tuple C. Slice the tuple D. Unpack the tuple

D. Unpack the tuple

Choose the correct statement: A. A variable name in Python cannot contain numbers. B. A variable value in Python cannot be updated. C. Variables are updated in Python using the keyword "new". D. Variable values in Python can change type from integer to string.

D. Variable values in Python can change type from integer to string.

Which command should you use to generate HTML documentation for a Python module named program.py? A. pydoc program B. pydoc -h program.py C. pydoc -t program.py D. pydoc -w program

D. pydoc -w program

Choose the item that best completes the following sentence: "After using an insert on a Python list..." A. one of the index values gets overwritten. B. an error occurs if the inserted object is not of the same type as the other list items. C. the length of the list remains the same. D. the length of the list increases by 1.

D. the length of the list increases by 1.

Function calls should be placed at the beginning of a code page, and functions should be placed later and toward the end of the code. T. True F. False

F. False

Nested Conditional code always runs all sub-conditions that are indented under if statements. T. True F. False

F. False

Python Function return values must be stored in variables. T. True F. False

F. False

The string method .swapcase () converts from string to integer. T. True F. False

F. False

True or False: When handling exceptions, Python code can include an else clause or a finally clause but not both. T. True F. False

False

Escape sequences start with a backslash (\). T. True F. False

T. True

Function names cannot begin with a number as the first character. T. True F. False

T. True

In Python, range (0,5) is equivalent to the list [0, 1, 2, 3, 4] T. True F. False

T. True

Like else, the elif can execute only when the previous if conditional evaluates False (shown in the below code sample). if response == 3: return "Correct" elif response <= 0: return "Correct" else: return "Incorrect" T. True F. False

T. True

The double equal sign(==) is used to compare values. T. True F. False

T. True

The first item in a Python List is at index 0 (zero). T. True F. False

T. True

The input () function in Python returns user input as a string. T. True F. False

T. True

True and False are Boolean keywords in Python. T. True F. False

T. True

Using comma separation, we can combine strings and numbers (int & float) in a single Python print () function without a TypeError. T. True F. False

T. True


Ensembles d'études connexes

SIE ( Understanding Products and Their Risks ) and (Understanding Trading, Customer Accounts, and Prohibited Activities)

View Set

DMI 65 Quiz 1 - Chapters 1 (1-60) 10 (61-79)

View Set

Animal Care and Use Program -ACUP

View Set