Coding Exercise #16
🌶️
👉 Here are four questions that will test your basic Python skills. Please click on the correct answer for each question.
1. One of the three code snippets below prints out a different output from the other two. Which one is it?
Code 1:
a = ['sarah', 'bill', 'anika']
for i in a:
print(i.capitalize())Code 2:
a = ['sarah', 'bill', 'anika']
print(a[0].capitalize())
print(a[1].capitalize())
print(a[2].capitalize())
Code 3:
a = ['sarah', 'bill', 'anika']
print([i.capitalize() for i in a])2. The two code blocks below do the same thing, but one is usually preferred over the other by best practices. Which one is the preferred one?
Code 1:
a = ['sarah', 'bill', 'anika']
b = [i.capitalize() for i in a]
print(b)
Code 2:
a = ['sarah', 'bill', 'anika']
b = []
for i in a:
b.append(i.capitalize())
print(b)3. Which of the following produces an error?
Code 1:
a = ['sarah', 'bill', 'anika']
a.append('jim')Code 2:
a = ('sarah', 'bill', 'anika')
a.append('jim')4. Select the wrong statement for the following code:
def foo(x, y):
print(x * y)
result = foo(10, 20)Subscribe below to get a new Python project or exercise daily or upgrade to our paid plan to view the archive of projects, exercises, and solutions.



Ardit, point 4 - option number 2 seems to be the wrong statement as the code prints 200 based on args/params provide when function is called with variable 'result'.