Question
Question 1. What is the output of the following code snippet? num_calories = dict(Coke=90, Coke_zero=0, Pepsi=94) for soda in num_calories.keys(): print (soda, end = )
Question 1.What is the output of the following code snippet? num_calories = dict(Coke=90, Coke_zero=0, Pepsi=94) for soda in num_calories.keys(): print(soda, end = )
Group of answer choices
Coke Coke_zero Pepsi
90 0 94
program error
{[Coke=90],[Coke_zero=0],[Pepsi=94]}
Question 2.Dictionaries are a collection of values indexed by _______:
Group of answer choices
variables
larches
keys
whole numbers
Question 3.Given the list nums = [[10, 20, 30], [98, 99]], what does nums[1][1] evaluate to?
Group of answer choices
30
99
98
[[98,99]]
Question 4.What is the output of the following code? class Time: """ A class that represents a time of day """ def __init__(self): self.hours = 0 self.minutes = 0 time1 = Time() # Create an instance of the Time class called time1 time1.hours = 7 time1.minutes = 30 time2 = Time() # Create a second instance called time2 time2.hours = 12 time2.minutes = 45 print('%d hours and %d minutes' % (time1.hours, time2.minutes))
Group of answer choices
7 hours and 30 minutes
12 hours and 45 minutes
7 hours and 45 minutes
12 hours and 30 minutes.
Question 5.What is the console output of the following Python script? Assume the user inputs the following string: 0 1 3 57 9. user_input = input('Enter numbers:') tokens = user_input.split() # Split into separate strings nums = [] for token in tokens: nums.append(int(token)) max_num = None for num in nums: if (max_num == None) and (num % 2 == 0): max_num = num elif (max_num != None) and (num > max_num ) and (num % 2 == 0): max_num = num print('Max #:', max_num)
Group of answer choices
1
57
0
9
Question 6.Complete the following code snippet so that all of the negative values my_dict will be changed to zero. for key, value in _______: if value my_dict[key] = 0
Group of answer choices
my_dict.values()
my_dict[keys]
my_dict
my_dict.items()
Question 7.What is the output of the following code snippet? my_list = [[25], [15, 25, 35], [10, 15]] sorted_list = sorted(my_list, key=max) print('Sorted list:', sorted_list)
Group of answer choices
[[25], [15, 25, 35], [10, 15]]
[[10, 15]]
[[25], [35], [15]]
[[10, 15], [25], [15, 25, 35]]
Question 8.A(n) ___________ method initializes a class.
Group of answer choices
__init__
initialization
dictionary
constructor
Question 9.Complete the following code snippet so that it will print the dictionary keys from my_dict. for key in ________: print key
Group of answer choices
my_dict.values()
my_dict[keys]
my_dict
keys[my_dict]
Question 10.A Python list is a _________, which is an object that groups related objects together.
Group of answer choices
larch
container
array
variable
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started