AND ANSWERS
What is the output of the following code?
print('abc', end with = 'period')
print('def', end = '*')
print('xyz') - ANSWER-'abcperioddef*xyz'
What is the output of the following code?
x = 5 + 2**3 // 3 - ANSWER-7
Which ones are valid variable names?
1. ____
2. 2abc00
3. false
4. all_$200
5. Num_of_students
6. - ANSWER-1, 3, 4, 5, 6
What is the output of this code?
a_list = ['a', 10, 1.23, 'Tom']
b_tuple = (1, 2, 3, 4, 5, 6)
print(a_list.index('Tom') + b_tuple.index(5) - ANSWER-7
When opening a file with the mode 'w' and if the file does NOT exist, what
happens? - ANSWER-The file is created
The name used to refer to the current instance in a class - ANSWER-self
what is an input converted to? - ANSWER-a string
what is the output of this code>
class Student:
.def __init__(self, name, id):
, .self.name = name
.self.id = id
.def print_info(self, address):
.self.address = address
.print(self.name)
.print(self.id)
.print(self.address)
s1 = Student('Tom Smith', 'G001')
s1.print('123 Main St') - ANSWER-Tom Smith
G001
123 Main St
what is the output for this code?
a_list = [-10, 10, -20, 20, -30, 30]
b_list = [i*10 if i > 0 else i + 10 for i in a_list]
print(b_list) - ANSWER-[0, 100, -10, 200, -20, 300]
The syntax for invoking a class method is the same as the syntax for calling
a function. - ANSWER-False
dict1 = {'a': 10, 'b': 20, 'c': 30}
dict2 = {'c': 30, 'a': 10, 'b': 20}
print(dict1 != dict2) - ANSWER-False
Class methods are defined within a class and perform some action helpful to
that specific type of object. - ANSWER-True
What is the output of the following code?
a = [1, 2, 3, 4]
print(a * 2) - ANSWER-[1, 2, 3, 4, 1, 2, 3, 4]
What is the output of the following program?
a = list('abcdefg')