Computer Programming Exam

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

def add_numbers(num_1, num_2):

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

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

True or False: Jupiter notebooks have code cells and markdown cells?

TypeError

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

false

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

NameError

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

str

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

int

What does type(1024) return?

float

What does type(3.55) return?

hashtag

What is a valid python comment?

python 3

What version of python does this course cover?

.upper()

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

true

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

line 1

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

lines 1 and 3

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?

312

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.

false

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

false

True of false? 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

True of false? In Python, strings can only contain letters a-z and A-Z

true

True or False? Variable values in Python can change type, from integer to string

true

True or false? Function names cannot begin with a number as the first character.

false

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

false

True or false? Python Function return values must be stored in variables.

false

True or false? Python cannot display quotes in strings using print().

false

True or false? The string method .swapcase() converts from string to integer.

true

True or false? True and False are Boolean keywords in Python.

true

True or false? Variable values in Python can change type, from integer to string

true

True or false? Variables in Python can be initialized using the equals sign (=).

true

True or false?The input() function in Python returns user input as a string.

true

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

answer = input("enter your answer: ")

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

you entered 38

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

TypeError

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

SyntaxError

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

13.0

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

"start the week!"

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

20

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

200

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

110

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

"return this lower"

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)

show_name()

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

"Be careful, hot plate!"

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?

"3556 is a new student"

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?

true

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

"Jin Xu is a string entry"

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?

true

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

false

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

"sKYE hOMSI"

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

num_1 + int(num_2)

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

It's time to code

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

"size is recorded"

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?

"Truck does not start with P"

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?

return int(ystr) - xint

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.

1.0

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

12.0

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

"2001 is all digits"

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


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

States and Matter Chemistry Unit test-96%

View Set

Ch 15 - Acute Respiratory Failure

View Set

PNE 111/Health & Disease/PrepU 37

View Set

Romeo and Juliet Act 1, Scene 5.

View Set

Module 5 Big Data Exam - STUDY SET.jtc3896

View Set

Digital and Social Media Marketing Midterm

View Set

llinois Driver's License test 2021

View Set