Unit 1 Exam

¡Supera tus tareas y exámenes ahora con Quizwiz!

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"

If book_title = "The Xylophone Case" which code will return True?

"x" in book_title

Which of the following is a valid Python comment structure?

# comment

Which is a valid Python code comment?

# use comments to describe the function of code.

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

*, /, +, -

Which operator can be used to combine two strings?

+

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

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

What are the advantages of creating and using functions in code? (Choose all that apply.)

- easier testing -code reuse

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

.upper()

Which contains only integers? (ignore the commas)

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

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

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

12

calculation = 5 + 15 / 5 + 3 * 2 - 1 print(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

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

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: 4 3rd input: five 4th input: 6

34

What is the value of x after the following code is run? x = 2 y = 1 x += y + 1

4

Which version of Python does this course cover?

Python 3

Which of the following statements is true?

Python variables are case sensitive

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

She said, "Who's there?"

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

SyntaxError

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 (=).

def ignore_case(name): answer = "" while answer.isalpha() == False: answer = input("enter last name: ") return answer.lower() == name.lower() When will the ignore_case function exit the while loop?

When only letters are entered at the input prompt

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

What does the input() function return?

a string value

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

an error message

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

answer = input("enter your answer: ")

What does type(1024) return?

int

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

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?

line 1 and 3

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

new_string = "Hello ' + "World!'

Which is a Python method of getting numeric input that can be used in math?

num1 = int(input("enter a number"))

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

num_1 + int(num_2)

Which of the following is a Python function?

print ()

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

print("Hello\nWorld!")

It's Python Time! Choose the code that will not create the output shown above.

print("It's" + "Python Time!")

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

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

\\\\ What is the best choice of code to create the output shown above?

print("\\\\\\\\")

What will be displayed by the following code? count = 0 while count < 5: print("Hello", end = " ") count +=1

Hello Hello Hello Hello Hello

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

It's time to code

if True: ifFalse: print("Banana") else: print("Apple") else: if True: print("Dates") else: print("Corn") What is the output of the above code?

No answer text provided.

while 3 < 5: is a forever loop just like while True: is.

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

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

x = 0 while x < 5: x += 1 print('loop') What is the output from running the above code most like?

"loop" (5 times)

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)

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

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"

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"

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

NameError

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

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

False

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

False

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

False

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

False

Python Function return values must be stored in variables.

False

Python cannot display quotes in strings using print().

False

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

False

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

False

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

False

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

False

while True: will loop forever but can be interrupted using the Python keyword "end" inside the loop.

False

Analyze the following code and choose the most correct statement: even = False if even = True: print("It is even!")

The program has a SyntaxError in line 2: if even = True:

What is "print" used for?

To display output

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

True

Escape sequences start with a backslash (\).

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

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

What does type(3.55) return?

float

count = 1 while count >= 1: print("loop") count +=1 What is the output from running the above code most like?

forever loop

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

print(s + 1)

Given the code below and entering "Colette" for user_name input: python total_cost = 22.95 user_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 = 3 y = "3" # get_diff takes an int and a str def 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

Which statement sets the variable s to a value of "Chapter1"?

s = "Chapter" + str(1)

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

show_name()

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

str

Which is not a possible "infinity/infinite" loop?

while 0 > 1:

For the code x >= y which x and y values evaluate True?

x = "a", y = "A"

if x < 0: print("-") else: if y >= 0: print("+/+") else: print("+/-") Which values for x and y result in the output "+/-"? (Choose the best answer.)

x = 0 and y = -1

if x < 0: print("-") else: if y >= 0: print("+/+") else: print("+/-") The nested conditional code is sure to be run if ___. (Choose the best answer.)

x = 1

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

x<3


Conjuntos de estudio relacionados

India under British Rule Assignment and Quiz

View Set

Quality and Performance test 9-13

View Set

Brown v Board Supreme Court Cases review

View Set

Skeletal System: Structure and Function

View Set

BIO 156 Mastering 9 (Ch 5 Part A)

View Set