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

ITS Python Practice Exam 2 - Python Programming Correctly Answered.

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

ITS Python Practice Exam 2 - Python Programming Correctly Answered. Using the dropdown arrows for the missing code pieces, complete the following code example so that it accomplishes the functionality of this game: A user gets five chances to correctly guess a whole number from 1 to 10. If the user guesses correctly, they get a congratulatory message and the game ends. If not, they get a message thanking them for playing. - CORRECT ANSWER from random import randint randint(1,10) A developer wants documentation for a function to display when called upon in a print statement. Use the drop-down menus to fill in the remainder of the code necessary to generate the documentation. - CORRECT ANSWER ''' ''' area.__doc__ Examine the following code: def area (width, height): area=width*height return area box1area=area(5,2) box2area=area(6) What needs to change in order for the height in the area function to be 12 if a height is not specified when calling the function? - CORRECT ANSWER def to def area (width, height=12) The proper syntax for pydoc is Python -m pydoc module where module represents the name of a Python module. - CORRECT ANSWER Yes Pydoc is a self-contained executable that can be run from a command-line prompt. - CORRECT ANSWER No Pydoc generates documentation of Python modules. - CORRECT ANSWER Yes A junior programmer enters the following code: height=5 width=5 if height==width print("You have a square") When trying to run the code, errors are generated. Which two fixes are necessary in order for this code to work? - CORRECT ANSWER A colon needs to be added at the end of the if condition. The print statement needs to be indented. A new Python developer is learning the code necessary to display dates in multiple formats. The developer has been tasked to create the following display with dates: The current date is 01/01/2023 The current weekday is: 6 Using the dropdown arrows, complete the code snippet necessary to create the display, leaving open the possibility of the time being displayed in the future. - CORRECT ANSWER import datetime datetime,() %m/%d/%Y weekday() Evaluate the following code example, whcih is an attempt to loop through and print a tuple of products by serial numher: products=("1111","2222","3333","4444","5555","6666","7777","8888","9999") for product in products: print(products[product]) The code, when run, is generating errors. Which fixes are needed to make the code work properly and return the list of products? - CORRECT ANSWER Change the print statement to print(product) Indent the print statement You are in the process of writing some code to divide two numbers. You want the result to display so long as there are no errors. If there are errors, you want to display a message indicating that the user either tried to divide by zero or used an invalid number. Using the dropdown arrows, fill in the missing keywords to make this happen. - CORRECT ANSWER try except a=float(input("Enter a number.")) b=float(input("Enter a number to divide by.")) try: print("This did not work. Did you try to divide by zero?") else: print("You successfully divided two numbers.") finally: print("Thank you for playing.") The finally statement will run regardless of which pieces of code above it run. Both the try and except parts will run if a=0 and b!=0. The else part will run if a=0 and b!=0 - CORRECT ANSWER Yes No Yes

Vista previa del contenido

ITS Python Practice Exam 2 - Python
Programming Correctly Answered.

Using the dropdown arrows for the missing code pieces, complete the following code example so that it
accomplishes the functionality of this game:



A user gets five chances to correctly guess a whole number from 1 to 10. If the user guesses correctly,
they get a congratulatory message and the game ends. If not, they get a message thanking them for
playing. - CORRECT ANSWER from random import randint

randint(1,10)



A developer wants documentation for a function to display when called upon in a print statement. Use
the drop-down menus to fill in the remainder of the code necessary to generate the documentation. -
CORRECT ANSWER '''

'''

area.__doc__



Examine the following code:

def area (width, height):

area=width*height

return area

box1area=area(5,2)

box2area=area(6)



What needs to change in order for the height in the area function to be 12 if a height is not specified
when calling the function? - CORRECT ANSWER def to def area (width, height=12)



The proper syntax for pydoc is Python -m pydoc module where module represents the name of a Python
module. - CORRECT ANSWER Yes

, Pydoc is a self-contained executable that can be run from a command-line prompt. - CORRECT ANSWER
No



Pydoc generates documentation of Python modules. - CORRECT ANSWER Yes



A junior programmer enters the following code:

height=5

width=5

if height==width

print("You have a square")



When trying to run the code, errors are generated. Which two fixes are necessary in order for this code
to work? - CORRECT ANSWER A colon needs to be added at the end of the if condition.

The print statement needs to be indented.



A new Python developer is learning the code necessary to display dates in multiple formats. The
developer has been tasked to create the following display with dates:

2023-01-01

The current date is 01/01/2023

The current weekday is: 6



Using the dropdown arrows, complete the code snippet necessary to create the display, leaving open
the possibility of the time being displayed in the future. - CORRECT ANSWER import datetime

datetime,datetime.now()

%m/%d/%Y

weekday()



Evaluate the following code example, whcih is an attempt to loop through and print a tuple of products
by serial numher:

products=("1111","2222","3333","4444","5555","6666","7777","8888","9999")

Información del documento

Subido en
6 de abril de 2025
Número de páginas
14
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.
ROSEGRADES
3.4
(35)
Vendido
236
Seguidores
87
Artículos
12121
Ú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