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