• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 2 out of 10 pages
Exam (elaborations)

Csc121 Python Exam Questions With Correct Answers

Document preview thumbnail
Preview 2 out of 10 pages

CSC121 PYTHON EXAM QUESTIONS WITH CORRECT ANSWERS

Content preview

CSC121 PYTHON EXAM QUESTIONS
WITH CORRECT ANSWERS

Which of the following would you use if an element is to be removed from a specific
index?

a remove method
an index method
a del statement
a slice method - Answer-a del statement

What will be the value of the variable num_list after the following code executes?
num_list = [1, 2, 3, 4]
num_list[3] = 10

[1, 2, 3, 10]
[1, 2, 10, 4]
[1, 10, 10, 10]
Nothing; this code is invalid - Answer-[1, 2, 3, 10]

The ________ method is commonly used to add items to a list. - Answer-append

Rewrite the following code with list comprehension:
list1 = [4, 7, 12, 8, 25]
list2 = []
for x in list1:
if x > 10:
list2.append(x*2)

A. list1 = [4, 7, 12, 8, 25]list2 = [x*2 for x in list1 if x > 10]
B. list1 = [4, 7, 12, 8, 25]list2 = x*2 for x in list1 if x > 10
C. list1 = [4, 7, 12, 8, 25]list2 = [for x*2 in list1 if x > 10]
D. list1 = [4, 7, 12, 8, 25]list2 = [x*2 if x > 10 in list1 ] - Answer-A. list1 = [4, 7, 12, 8,
25]list2 = [x*2 for x in list1 if x > 10]

The primary difference between a tuple and a list is that

you don't use commas to separate elements in a tuple

, once a tuple is created, it cannot be changed
a tuple cannot include lists as elements
a tuple can only include string elements - Answer-once a tuple is created, it cannot be
changed

What will be the value of the variable list after the following code executes?
list = [1, 2]
list = list * 3

[3, 6]
[1, 2], [1, 2], [1, 2]
[1, 2, 1, 2, 1, 2]
[1, 2] * 3 - Answer-[1, 2, 1, 2, 1, 2]

When working with multiple sets of data, like a table made up of rows and columns, one
would typically use a(n)

tuple
list
nested list
sequence - Answer-nested list

Which of the follow will display "Found it!" if the string 'May 4' is found in the list
appointments? - Answer-if 'May 4' in appointments:
print('Found it!')

The index of the first element in a list is 1, the index of the second element is 2, and so
forth. TRUE OR FALSE - Answer-fALSE

The ________ function can be used to convert a list to a tuple. - Answer-TUPLE

Given the following list comprehension, write the equivalent code without using list
comprehension:
list1 =[[x,y] for x in range(3) for y in range(2) if (x + y) % 2 == 0] - Answer-.
list1 = []
for x in range(3):
for y in range(2):
if (x + y ) % 2 == 0:
list1.append([x,y])

What is an advantage of using a tuple rather than a list?

Tuples can include any data as an element.
Tuples are not limited in size.
Processing a tuple is faster than processing a list.

Document information

Uploaded on
June 14, 2025
Number of pages
10
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers
$13.49

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
Perfectscorer
3.6
(77)
Sold
512
Followers
355
Items
9481
Last sold
2 weeks ago




Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions