Python Unit Test

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

answer = input("enter your answer: ") print("You entered " + answer) If user input is 38, what is the output of the above code?

You entered 38

Which version of Python does this course cover?

Python 3

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

.upper()

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

1.0

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

13.0

def add_num(num_1 = 10): print(num_1 + num_1) Choose the correct output of calling the above function using the following code: add_num()

20

num_1 = ""num_temp = ""num_final = ""while True: num_1 = input("Enter an integer: ") if num_1.isdigit(): num_final = num_temp + num_1 num_temp = num_final else: print(num_final) break What is the output from running the above code using the following input at the Enter an integer: prompt? 1st input: 3 2nd input: 43rd input: five4th input: 6

34

In Python string comparisons, lower case "a" is less than upper case "A".

False

In Python we can use the "+" operator to add numbers but not to add strings.

False

In Python, strings can contain only letters a-z and A-Z.

False

Python Function return values must be stored in variables.

False

greet(name) 2. name = input("enter your name: ") 3. greet(name) 4. def greet(person): 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?

Lines 1 and 3

assignment = 25if assignment = 25: print('use "=" to assign values')else: pass What is the output of the above code?

SyntaxError

"Hello".isalpha() What is the output of the above code?

True

For the code: x = 3 + 9 * 2, the value of x is 21 when applying order of operations.

True

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

True

Jupyter Notebooks have code cells and markdown cells.

True

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

TypeError

answer = input("enter your answer: ") print(10 + answer) If user input is 38, what is the output of the above code?

TypeError

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

answer = input("enter your answer: ")

What does type(1024) return?

int

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

new_string = "Hello " + "World!"

num_1 = 3num_2 = "8" What is the minimum code to mathematically add num_1 to num_2?

num_1 + int(num_2)

def show_name(): print("Tobias Ledford") Which code calls the function in the above code?

show_name()

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

str

Choose the correct statement.

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

Choose the correct statement.

Variables in Python can be initialized using the equals sign (=).

size_num = "8 9 10"size = "8" # user inputif 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"

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

"Start the week"

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

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"

name = "skye homsi" name_1 = name.title()name_2 = name_1.swapcase()print(name_2) What is the output from the above code?

"sKYE hOMSI"

Python cannot display quotes in strings using print().

False

The code print("I am", 17, "years old") will output: I am 17 years old

False

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

False

Given x = 9, which line of code will evaluate False?

"x<3"

The type() function is used to change from one data type to another.

False

Which is a valid Python code comment?

# use comments to describe the function of code

Which contains only integers?

1, 2, 0, -3, 2, -5

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

False

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

x = 3y = 4calculation = x*yprint(calculation) What is the best estimate for the output of the above code?

12

def add_num(num_1 = 10): return num_1 + num_1 Choose the correct output of calling the function above using the following code: print(add_num(100))

200

1. name = input("enter your name") 2. print(name, "your score is", score) 3. score = 199 Order the above numbered code lines into the proper sequence.

3,1,2

What does type(3.55) return?

Float

hot_plate = Trueif 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"

year = "2001" if year.isdigit(): print(year, "is all digits") else: pass What is the output from running the above code?

"2001 is all digits"

id = 3556if 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?

"3365 is a new student"

print("It's time to code") What is the output of the above code?

It's time to code.

1. 2. score = add_score(190) 3. 4. print(name, "your score is", score) 5. At which line above should the following add_score() function definition be inserted so the program runs without error? def add_score(current): return current + 10

Line 1

PriNt("Hello World!") will not output the message "Hello World!".

NameError

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

Shift + r

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

length = "33"length.isalnum() What is the output of the above code?

True

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

True

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

def add_numbers(num_1, num_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

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

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

Given the code below and entering "Colette" for user_name input: python total_cost = 22.95user_name = input("Enter your name: ") Choose the print statement that will output: Colette - the total is $ 22.95 for today's purchase

print(user_name, "- the total is $", total_cost, "for today's purchase")

x = 3y = "3" # get_diff takes an int and a strdef get_diff(xint, ystr): # <function code needed here>if y.isdigit() == False: print('"y" is not an integer string')elif get_diff(x,y) == 0: print('x equal to y')else: print('x is NOT equal to y') To make this program work, printing "x equal to y", choose the best code to replace the above comment "# <function code needed here> " in the get_diff function.

return int(ystr) - xint


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

Psych 100a: Quiz 9 - Paired-Samples t

View Set

Chapter 40: Management of Patients with Gastric and Duodenal Disorders

View Set

Таблица умножения на русском языке / Times Tables / English /

View Set

D216 Unit 6: Forms of Business Organization (14%)

View Set

Chapter 12 Cardiovascular system Mid term

View Set

Care of Dental Appliances and Prostheses

View Set