• ¿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 7 páginas
Examen

Intro to Programming Logic Final Exam Questions with Complete Solutions

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

Intro to Programming Logic Final Exam Questions with Complete Solutions

Vista previa del contenido

Intro to Programming Logic Final Exam
Questions with Complete Solutions

Write a statement that creates a list with the following strings: 'Einstein', 'Newton',
'Copernicus', and 'Kepler' . - ANSWER-names = ['Einstein', 'Newton', 'Copernicus',
'Kepler']

Assume names references a list. Write a for loop that displays each element of the
list. - ANSWER-for element in names:
print(element)

Assume the list of numbers1 has 100 elements, and numbers2 is an empty list. Write
code that copies the values in numbers1 to numbers2. - ANSWER-for item in
numbers1:
numbers2.append(item)

What will the following code print?

list1 = [40, 50, 60 ]
list2 = [ 10, 20, 30 ]
list3 = list1 + list2
print (list3) - ANSWER-[40, 50, 60, 10, 20, 30].

What does the following of the code display?

mystr = 'yes'
mystr += 'no'
mystr += 'yes'
print (mystr) - ANSWER-yesnoyes

What does the following code display?

mystr = 'abc' * 3
print (mystr) - ANSWER-abcabcabc

What will the following code display?

mystring = 'abcdefg'
print (mystring [2:5] ) - ANSWER-cde

What does the following code display?

numbers = [1, 2, 3, 4, 5, 6, 7 ]
print (numbers [4 : 6] ) - ANSWER-[5, 6]

What does the following code display?

, name = 'joe'

print (name . lower ( ) )
print (name. upper ( ) )
print (name) - ANSWER-joe
JOE
joe
joe

Assume choice references a string. The following if statement determines whether
choice is equal to 'Y' or 'y':

if choice == 'Y' or choice == 'y' :

Rewrite this statement so it only makes one comparison, and does not use the or
operator. (Hint: use either the upper or lower methods. ) - ANSWER-if choice.upper()
== 'Y'

Write a loop that counts the number of digits that appear in the string referenced by
mystring. - ANSWER-counter = 0
for ch in mystring:
if ch.isdigit():
counter +=1
print ('The number of digits is', counter)

Write a function that accepts a string as an argument and returns true if the
argument ends with the substring ' .com ' . Otherwise, the function should return
false. - ANSWER-def com_check(mystring):
if mystring.endswith('.com'):
return True
return False

Assume mystring references a string. Write a statement that uses a slicing
expression and displays the first 3 characters in the string. - ANSWER-
print(mystring[:3])

Look at the following statement:

mystring= ' cookies>milk>fudge>cake>ice cream '

Write a statement that splits this string, creating the following list:

[ 'cookies' , 'milk' , 'fudge' , 'cake' , 'ice cream' ] - ANSWER-mylist = mystring.split('>')

What will be the output after the following code is executed?

def pass_it(x, y):

z = x + ", " + y

Información del documento

Subido en
22 de marzo de 2025
Número de páginas
7
Escrito en
2024/2025
Tipo
Examen
Contiene
Preguntas y respuestas
$14.99

¿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.
lectknancy
3.8
(84)
Vendido
346
Seguidores
28
Artículos
26318
Última venta
2 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