Final Exam
What symbol is used to delineate one line comments in code?
#
What will be displayed on screen given the following code? for i in range(0, -3, -1): print(i)
0 -1 -2
How many parameters are required by the draw_square function in the code below? cr = '#' def draw_square(size): for h in range(size): for w in range(size): print(cr, end='') print() def draw_rect(height, width): for h in range(height): for w in range(width): print(cr, end='') print()
1
What will be displayed on screen when the following code executes? for i3 in range(10,50,10): print(i3)
10 20 30 40
What user input would result in the following output, given the following if-elif-else statements: You are ok to view PG-13 movies! That's all folks! age2 = input() age2 = int(age2) if age2 <= 9: rating = 'G' elif age2 <= 12: rating = 'PG' elif age2 <= 16: rating = 'PG-13' else: rating = 'R' print("You are ok to view "+rating+" movies!") print("That's all folks!")
13
What will be displayed on screen if the user input is 2008 user_num7 = input() user_num7 = int(user_num7) if user_num7 == 2001: print(user_num7,': Twin Towers') elif user_num7 == 2008: print(user_num7,': Great Recession') elif user_num7 == 2017: print(user_num7,': Hurricane Maria') else: print('No Disasters!')
2008 : Great Recession
How many parameters are there in the pyramid_volume function called in the following code? print('Volume for 4.5, 2.1, 3.0 is:', pyramid_volume(4.5, 2.1, 3.0))
3
What is the value of x after all the following statements execute? x = [100,200,300,400] x.append(500) x = tuple(x) x = len(x)
5
What will be displayed on screen when the following code executes? for i3 in range(5,-10,-5): print(i3)
5 0 -5
What is the value assigned to the variable name price when all the following statements are executed, and the user enters 50? price = input('how much is that dog in the window? ') price = float(price)
50.0
What is the value assigned to x? x = 5 * (38 % 7) + (3 + 4)^2
64
What is the value of x after all of the following statements execute? x = (10,20,30,40) y = list(x) y.pop(2) x = tuple(y) x = sum(x
70
What is the value of x after the following statements execute? x = 88 y = str(88) x = y x = x+y
8888
What will be the last line displayed on screen when the following code is executed? user_string2 = ('k','l','m','n','o','p') for letter2 in reversed(user_string2): print(letter2) print("Done!")
Done!
What will be displayed on screen if the user input is 1990 user_entry = input() user_entry = int(user_entry) if user_entry >= 1996: print('GenZ') elif user_entry >= 1979: print('GenY') elif user_entry >= 1964: print('GenX') else: print('Baby boomer or older')
GenY
What is a program that executes computer code?
Interpreter
What will be displayed on screen if the user input is 2019 user_num7 = input() user_num7 = int(user_num7) if user_num7 == 2001: print(user_num7,': Twin Towers') elif user_num7 == 2008: print(user_num7,': Great Recession') elif user_num7 == 2017: print(user_num7,': Hurricane Maria') else: print('No Disasters!')
No Disasters!
What is volatile storage with faster access usually located off a processor chip?
RAM
Given the following code: iteratem = input("How many movies? ") iteratem = int(iteratem) moviestring = ' ' for i in range(iteratem): movietitle = input("Movie? ") moviestring = moviestring + ' ' + movietitle print("The movies on your list are:"+moviestring) What would be displayed on screen after all the code executes and the user provides the following input (one at a time, in sequence) in response to the question Movie? Gloria Roma Gravity
The movies on your list are: Gloria Roma Gravity
What is displayed on screen after the following statements execute? y = (5,10,15,20) s = sum(y) t = len(y) x = s/t print('The result is: '+x+'!')
The result is: 12.5!
Given the following code: def print_total_inches(num_feet, num_inches): print("Total inches:", num_feet*12+num_inches) What will be displayed on screen when the following code is executed? print_total_inches(5, 8)
Total inches: 68
What will be displayed on screen after the following statement executes, given that total_grade = 88? print('Your final grade is',total_grade,'out of 100 possible points')
Your final grade is 88 out of 100 possible points
What will be displayed on screen after the following statement executes, given that total_grade = 88? print('Your final grade is'+str(total_grade)+'out of 100 possible points')
Your final grade is88out of 100 possible points
What will be displayed on screen after the following statement executes, given that total_grade = 88? print('Your final grade is: '+str(total_grade)+'!')
Your final grade is: 88!
What code would you change below to add a prompt to ask the user for his/her age to determine movies he/she can view? You are ok to view R movies! That's all folks! age2 = input() age2 = int(age2) if age2 <= 9: rating = 'G' elif age2 <= 12: rating = 'PG' elif age2 <= 16: rating = 'PG-13' else: rating = 'R' print("You are ok to view "+rating+" movies!") print("That's all folks!")
age2 = input()
Which line asks the user for the sentinel value? answer = 'y' while answer != 'n': s = input("Song?") print(s) answer = input("Continue (y/n)?") print("Thank you for playing")
answer = input("Continue (y/n)?")
Given the following code: user_string = ('a','b','c','d','e','f') for letter in user_string: print(letter) print("Done!") What will be the third line displayed on screen when the code executes?
c
A website lists the calories expended by men and women during exercise as follows: Men: Calories = [(Age × 0.2017) — (Weight × 0.09036) + (Heart Rate × 0.6309) — 55.0969] × Time / 4.184 Women: Calories = [(Age × 0.074) — (Weight × 0.05741) + (Heart Rate × 0.4472) — 20.4022] × Time / 4.184 What is one way you would edit the text above to write it in programming notation?
change x to *
Given the following code: cheer = "Go Warriors!" for cheerl in cheer: print(cheerl) for cheerr in reversed(cheer): print(cheerr) print("The entered cheer was:",cheer) What is the loop variable is used to print the variable cheer?
cheerl
What code may be used to save a dataframe to a csv file with pandas?
clothesdf.to_csv("clothing2.csv")
What will be displayed on screen when the following code executes? num_puppies = 4 if num_puppies != 4: print('b') else: print('d') print('g')
d g
Which loop is best to use when accessing the elements of a container, as when adding 1 to every element in a list, or printing the key of every entry in a dict, etc.
for loop
Which is a statement that imports only the function factorial from my_funcs.py.
from my_funcs import factorial
What would be displayed on screen, given the following code? user_name2 = 'erehwon' for name_letter2 in reversed(user_name2): print(name_letter2) print("The End!")
n o w h e r e The End!
What python standard library module could be used to: Get the name of the current operating system
os
What will be the first line displayed on screen when the following code is executed? user_string2 = ('k','l','m','n','o','p') for letter2 in reversed(user_string2): print(letter2) print("Done!")
p
Which line is not part of the loop body? answer = 'y' while answer != 'n': s = input("Song?") print(s) answer = input("Continue (y/n)?") print("Thank you for playing")
print("Thank you for playing")
Which line is not part of the loop body? iterateb = input("How many books? ") iterateb = int(iterateb) bookstring = ' ' for i in range(iterateb): booktitle = input("Book? ") bookstring = bookstring + ' ' + booktitle print("The books on your list are:"+bookstring)
print("The books on your list are:"+bookstring)
What print statement will print the following on screen? Given that height = 60 weight = 120 bmi = 24.333333333333332 With a height of 60 and weight of 120 your BMI is 24.333333333333332
print("With a height of",height,"and weight of",weight,"your BMI is",bmi)
Given the following variable names assigned with the following values as written: year = 2019 movie = 'Green Book' What statement will print the following on screen? 2019 best movie Oscar winner is Green Book!
print(str(year)+' '+'best movie Oscar winner is '+movie+'!')
How would you call the following function: def print_shape(): print('***') print('***') print('***') return to display 6 lines of 3 asterisks, such as: *** *** *** *** *** **
print_shape() print_shape()
A website lists the calories expended by men and women during exercise as follows: Men: Calories = [(Age × 0.2017) — (Weight × 0.09036) + (Heart Rate × 0.6309) — 55.0969] × Time / 4.184 Women: Calories = [(Age × 0.074) — (Weight × 0.05741) + (Heart Rate × 0.4472) — 20.4022] × Time / 4.184 What is one way you would edit the text above to write it in programming notation?
replace spaces in variable names with underscores
What data type is created with the following statement? z = '55
string
What is the data type of the value assigned to y as the result of the following statements? y = '66' y = int(y) y = float(y) y = str(y)
string
What is the data type of x when all the following statements have executed? x = 99 y = str(x) x = y
string
Which symbol is used to delineate docstrings for comments in code?
three consecutive "
How would one assign the Tops column of a dataframe named clothesdf to the list named topslist?
topslist = list(clothesdf.Tops)
What is the data type created with the following statement? integers5=(100,99,34,45,66)
tuple
The following is an example of what type of error? lyric = 99 + " bottles of pop on the wall"
type error
Which loop is best to use when the number of iterations is not computable before entering the loop, as when iterating until a user enters a particular character.
while loop