Python Exam

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

When using the str.format() method, which flag places a - (negative sign) in front of negative numbers?

"

Which statements evaluate True and without errors? (Choose all that apply.)

"The Title".istitle() "upper".islower()

When using printf-style string formatting, which conversion flag outputs a signed integer decimal?

%d

What is the order of precedence (from first to last) of the math operators?

*, /, +, -

Which operator can be used to combine two strings?

+

Which code will result in the ltr_cnt = 2 for counting the letter "c" found in the following test_string? test_string = 'Mexico City'

-

Which string method returns a index of first character or substring matches?

.find()

To move the pointer in an open file to the first character, what should you use?

.seek(0)

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

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

Which answer best describes what .strip() does in the following code sample? poem_line = poe1.readline().strip()

.strip() removes all whitespace in a string, including the '\n' formatting character

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

.upper()

When using Python, which athematic 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

What is the output of the following code? name = 123 if name.startswith("a") print("welcome")

An error message

Which code is the best use of Python to iterate through the list "numbers"? numbers = [7, 1, 5, 8, 0]

for range[5] in numbers: for int in list: for number in numbers: NONE OF THE ABOVE

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

from xyz import abc

Which process does Python use to optimize dictionary search capabilities?

hashing

Which Boolean operator has the highest precedence? (Choose one.)

is not

1. greet(name) 2. name = input("enter your name: ") 3. greet(name) 4. def greet(person): u 5. print("Hi,", person) 6. greet(name) Which line or lines need to be removed from the above code so the program prints a greeting without error

linens 1 and 3

Which is the best choice to complete the following sentence? Opening a file in Python using read mode ('r')...

makes file contents available for Python to read fro the file

Which function from the math module can you use to round up the number 12.34 to 13?

math.cell()

Which code overwrites (replaces) the "0" with a "5" in the following numbers list? numbers = [1, 1, 0]

numbers[2] = 5

Which function can you use to list the contents of the current working directory?

os.listdir()

Which type of statement should you use as a placeholder for future function code?

pass

Hello World! What is the best choice of code to create the output shown above?

print("Hello\nWorld!")

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

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

Which is valid Python code that will print "Green", give the following code? colors = ["Red", "Blue", "Green", "Yellow"]

print(colors[2])

Which Python code results in output of a sorted scores list with changing the original scores list below to be in a sort order? scores = [0, 5, 2, 11, 1, 9, 7]

print(scores.sort())

Choose the statement that will print the letter "d", give the variable declaration word = "windows".

print(word[3])

Which choice will print the word "tac", given the following variable declaration? word = "cat"

print(word[::-1])

Which function returns only whole, even numbers from within the range from 1 to 100?

random.randrange(2, 101, 2)

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

Which choice will return -1, given the following variable assignment below? word = "Python"

word.find("Z")

Given the following string: S = "Welcome: which code results in an error?

Print(S+1)

What is the output of the following code? print("She said, \ "Who's there?\")

She said, "Who's there?"

Which is not a way to run a code cell in Jupyter Notebook?

Shift + R

Which string defines heterogeneous tuple?

T = ("Tobias", 23, 25.3, [])

Which is an example of Python string addition that will run without error?

Falsenew_string = "Hello": + "World!"

Which attributes can you define for a time object? (Choose all that apply.)

Hour Second

Which two statements about key:value pairs are correct? (Choose two)

Keys are unique A value can be associated with multiple keys

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

NameError

What type of loop should you use to iterate over the elements of a simple table (two-dimensional list)?

Nested

vehicle_type = "Truck" if vehicle_type.upper().startswith("P"): print(vehicle_type, 'starts with "P"') else: print(vehicle_type, 'does not start with "P"') What is the output from running the above code?

Truck does not start with "P"

name = "SKYE HOMSI" print("y" in name.lower()) What is the output from the above code?

True

Which best describes the valid Python use of the following days List?

days.append("Wednesday") days.append(14) print(days[-1]) ALL OF THE ABOVE

A function with 2 integer parameters could start with which definition?

def add_numbers(num_1, num_2):

Which code is the best use of Python that deletes the "5" i the following numbers list? numbers = [7, 1, 5, 8, 0]

del numbers[2]


संबंधित स्टडी सेट्स

Pág. 19. Campos de estudio de la Economía, Demografía y Etnología. Estudiar Glosario

View Set

Lewis Chapter 68: Emergency and Disaster Nursing

View Set

Assingment #4: Corona virus article

View Set

Physics B - Introduction of Waves

View Set

Fair Housing CAM Certified Apartment Manager

View Set