CS 1400 Final Exam PDF
Document Details
Uploaded by Deleted User
Tags
Summary
This document appears to be a past paper or practice exam for a Python computer science programming course (e.g. CS 1400). It contains questions related to variables, functions, errors, and print statements in Python. The specific topics of the test seem to be an introduction to Python programming.
Full Transcript
In an instruction like: z = x + y, the symbols x, y, and z are examples of _____. variables Which symbol is used in Python to create a comment? # Which function converts a string to an integer? int() Dividing by zero is an example of which type of error? runtime What is an IDE used for? Program...
In an instruction like: z = x + y, the symbols x, y, and z are examples of _____. variables Which symbol is used in Python to create a comment? # Which function converts a string to an integer? int() Dividing by zero is an example of which type of error? runtime What is an IDE used for? Program development, including writing the source code. 15 _____ 3 = 0 % Which print statement would display: I won't quit! print('I won\'t quit!') What is the name of the data type used for floating point numbers? Float What is the value of x after the following code is executed? -2 A _____ is a word that is part of the Python language and can't be used as a variable name. Keyword What is the value of: 1 + int(3.5) / 2? 2.5 Which print statement displays: 'Tokyo had 9.273000 million people in 2015'? print(f'{"Tokyo":s} had {9.273:f} million people in {2015:d}') Which of the following statements removes the value ‘Google’ from the set, companies? companies = { ‘Apple’, ‘Microsoft’, ‘Google’, ‘Amazon’ } companies.remove(‘Google’) What are the contents of names_list after the following code is executed? names_list = [‘one’, ‘two’, ‘three’] digits_list = [‘1’, ‘2’, ‘3’] names_list = names_list + digits_list [‘one’, ‘two’, ‘three’, ‘1’, ‘2’, ‘3’] If text_line = 'one fish two fish', what is the value of text_line? ‘S’ To quit, a user types 'q'. To continue, a user types any other key. Which expression evaluates to true if a user should continue? key != 'q' For what values of x will "Medium" be output? If x > 40: Output "Large" Else If x > 20: Output "Medium" Else If x > 10: Output "Small" Any x from 21 to 40 With the logic block shown below, what is output when grade is assigned with the value 75? If grade < 50 Put "F" to output Else If grade < 60 Put "D" to output Else If grade < 75 Put "C" to output Else If grade < 85 Put "B" to output Else If grade 10 and days_since_login < 20: Which operator is evaluated first: x + y < y - z * 2 ? * Loops can only work with positive values. No negative values can be used. False A(n) __________ is the word used to describe each cycle or repetition through a loop. Iteration Infinite loops are usually favorable because they ensure that the program will continue running and operating as intended. False What is the name of the value that can be used to immediately end or terminate a loop? (Agent Smith: "Never send a human to do a machine's job.") sentinel Which term accurately describes placing one loop inside of another loop? Nesting Given the following function. To change the function to return the product instead of the sum, how many lines of code need to be changed? def calculate(a, b): return a + b print(calculate(3, 4)) print(calculate(5, 2)) print(calculate(6, 7)) 1 What is the output? def print_water_temp_for_coffee(temp): if temp < 195: print('Too cold.') elif (temp >= 195) and (temp 205): print('Too hot.') print_water_temp_for_coffee(205) print_water_temp_for_coffee(190) Perfect temperature. Too cold. What is output? def calc(num1, num2): return 1 + num1 + num2 print(calc(4, 5), calc(1, 2)) 10 4 After a function's last statement is executed, the program returns to the next line after the _____. function call In the following code, the variable val is the function call's _____. def calc_square_area(size): area = size * size return area val = float(input('Enter size of square: ')) square_area = calc_square_area(val) print(f'A square of size {val} has area {square_area}') Argument ________ are designed to handle error or other unusual cases in a program. Exceptions Which of the following is not a language keyword related to exception handling? Throwing Which of the following is a common exception type in Python? EOFError ZeroDivisionError ValueError The same code can have multiple exception handlers. True The programmer is able to define their own exception types. true