• ¿Documento equivocado? Cámbialo gratis
  • Escrito por estudiantes que aprobaron
  • Inmediatamente disponible después del pago
  • Leer en línea o como PDF
Vender
¿Dónde estudias?
Tu idioma
Document preview thumbnail
Vista previa 2 fuera de 10 páginas
Examen

Csc121 Python Exam Questions With Correct Answers

Document preview thumbnail
Vista previa 2 fuera de 10 páginas

CSC121 PYTHON EXAM QUESTIONS WITH CORRECT ANSWERS

Vista previa del contenido

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.

Información del documento

Subido en
14 de junio de 2025
Número de páginas
10
Escrito en
2024/2025
Tipo
Examen
Contiene
Preguntas y respuestas
$13.49

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Seller avatar
Los indicadores de reputación están sujetos a la cantidad de artículos vendidos por una tarifa y las reseñas que ha recibido por esos documentos. Hay tres niveles: Bronce, Plata y Oro. Cuanto mayor reputación, más podrás confiar en la calidad del trabajo del vendedor.
Perfectscorer
3.6
(77)
Vendido
512
Seguidores
355
Artículos
9481
Última venta
3 semanas hace




Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes