• 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 14 pages
Exam (elaborations)

ITS Python Practice Exam 2 - Python Programming Correctly Answered.

Document preview thumbnail
Preview 2 out of 14 pages

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

Content preview

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")

Document information

Uploaded on
April 6, 2025
Number of pages
14
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.
ROSEGRADES
3.4
(35)
Sold
236
Followers
87
Items
12121
Last sold
3 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