python programming // exam review

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

PriNt ("Hello World!") will not output the message "Hello World!". What will it result in?

NameError

What does type(3.55) return?

float

What does type("Hello World!") return?

str

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?

"3556 is a new student"

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.

3,1,2

In Python, what is the base class for all built-in exceptions?

BaseException

name = "Tobias" print(name == "Alton") What is the output from running the above code?

False

Which command should you use to generate HTML documentation for a Python module named program.py?

pydoc -w program

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.

"Be careful, hot plate!"

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?

"Jin Xu is a string entry"

day = "monday" if day.capitalize() == "Monday": print("Start the week!") else: pass What is the output from running the above code?

"Start the week!"

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)

"ite"

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)

"return this lower"

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?

"run forever" (10 times)

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?

"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?

"time is 3" & "time is 4"

In an os function, which syntax can you use to move up one folder in the current directory structure?

..

Which function displays a datetime.date object in the form Monday, January 01, 2018?

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

Which code formats the string "Green" to "GREEN"?

.upper()

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?"

0

x = 3 y = 3 calculation = x/y print(calculation) What is the best estimate for the output of the above code?

1.0

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))

110

calculation = 5 + 15 / 5 + 3 * 2 - 1 print(calculation) What is the best estimate for the output of the above code?

13.0

When using Python, which mathematic operation returns a value of 2?

42 % 4

When using Python, what is the result of the mathematic operation 1 ** (2 * 3) / 4 + 5?

5.25

Which of the following statements about tuples is true?

A tuple can contain list elements.

Which of the following data/inputs Cannot be contained in a variable:

All can be assigned to a variable

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)

Dubai

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

False

The string method .swapcase () converts from string to integer.

False

Which two staements about the pydoc module are true?

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

Escape sequences start with a backslash (\).

True

In Python, range (0,5) is equivalent to the list [0, 1, 2, 3, 4]

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"

True

The double equal sign(==) is used to compare values.

True

The first item in a Python List is at index 0 (zero).

True

The input () function in Python returns user input as a string.

True

True and False are Boolean keywords in Python.

True

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

True

What does the Python code: score = 3 + "45" result in?

TypeError

Which process can you use to assign the values of a tuple to multiple variables?

Unpack the tuple

Choose the correct statement:

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

Which statement about local variables is true?

You can use the same variable name in multiple functions.

Which is an example of the proper use of the Python input () function?

answer = input("enter your answer:")

Which information should you include in a multi-line docstring for a function?

arguments, return values, and exceptions

Choose the item that best completes the sentence: "A Python list..."

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

Choose the item that best completes the following sentence: "A Python list..."

can contain both strings and numbers together as list items.

Which code is the best use of Python that deletes the "5" in the following numbers list?

del numbers[2]

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.

false

Python Function return values must be stored in variables.

false

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

false

Which clause should you use for code that you want to execute regardless of whether an exception is raised?

finally

Which three data types can you use for dictionary keys? (Choose three.)

float, int, string

Which code should you use to import a function named abc from a Python module named xyz?

from xyz import abc

Which code overwrites (replaces) the "0" with a "5" in the following numbers list?

numbers[2] = 5

Which is a properly formatted Python print () function example?

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?

print(scores.sort())

Which statement best describes a String in Python/Computer Science?

sequence of characters

Choose the item that best completes the following sentence: "After using an insert on a Python list..."

the length of the list increases by 1.

Function names cannot begin with a number as the first character.

true


Set pelajaran terkait

Chemolithotrophs Sulfur and Iron Oxidizing bacteria

View Set

Vulnerability and Hazard Exposure

View Set

3.04 Defend, Challenge, or Qualify

View Set

Major Lines of Latitude and Longitude

View Set

Quiz 33-Chi-Square test for independence

View Set