Looking for Basics in Computer Programming test answers and solutions? Browse our comprehensive collection of verified answers for Basics in Computer Programming at moodle.modul.ac.at.
Get instant access to accurate answers and detailed explanations for your course questions. Our community-driven platform helps students succeed!
Consider the stack trace below. What is the problem?
File "C:\Users\lyndo\.spyder-py3\foundations\errors.py", line 21, in <module>
z = double()
File "C:\Users\lyndo\.spyder-py3\foundations\errors.py", line 14, in double
return xx
NameError: name 'xx' is not defined
Consider the code below. What will be printed out?
X = “giraffe”
Y = [“iterative”, “recursively”, “functional”]
if len(X)<6:
raise ValueError(“Too short!”)
if X[0] > ‘n’:
raise IndexError(“Another word please.”)
if X in Y:
raise TypeError(“Word is forbidden.”)
Consider the code below. Which error will be thrown?
y = 12
print(“How many eggs in a dozen?” + y)
How would you define your own error type in Python as a child of the NameError type?
Consider the code below. What will be printed out?
try:
i=4
j=[2,4,6,8]
print(j[i])
except IndexError:
print(“Oops! Error.”)
else:
print(“All OK.”)
finally:
print(“Bye bye.”)
What is the output of the below code?
list = [‘apples’, ‘bananas’, ‘pears’]
string = “;”.join(list)
print(string)
Which is the correct way to write to a CSV file including headers for our data? (We have done ‘import csv’, our file object is called ‘f’ and our headers are stored in a variable called ‘headers’)
What would the below code do?
with open(“text.txt”) as f:
for line in f:
print(line.replace(‘ ‘,’’))
Which is the correct syntax to get the user’s name as input?
What is the output of the below code?
message = “My name is {}, I am {:.2f}% Irish”.format(“Sean”,14.7)