Questions and Correct Answers | Graded
A+ | Verified Answers | Just Released
The following session calls the string object s's object's lower and upper methods,
which produce new strings containing all-lowercase and all-uppercase versions of
the original string, leaving s unchanged:
In [1]: s = 'Hello'In [2]: s.lower() # call lower method on string object sOut[2]:
'hello'In [3]: s.upper()Out[3]: 'HELLO'
After the preceding session, s contains 'HELLO'. ---------CORRECT ANSWER-----------
------False
The following code produces different values are likely to be displayed each time
you run the code:
import randomfor roll in range(10):print(random.randrange(1, 6), end=' ') ---------
CORRECT ANSWER-----------------True
Based on the following function definition that can receive an arbitrary number of
arguments:
In [1]: def average(*args):...: return sum(args) / len(args)...:
which of the following statements is false? ---------CORRECT ANSWER-----------------
All of the above are true.
,The value of the expression of:
In [1]: floor(-3.14159) ---------CORRECT ANSWER------------------4.0
Which of the following statements is false?
-Each function should perform a single, well-defined task.
-The following code calls function square twice. The first call produces the int
value 49 and the second call produces the int value 0:
In [1]: def square(number):...: """Calculate the square of a number.""" ...: return
number ** 2 ...: In [2]: square(7)Out[2]: 49In [3]: square(.1)Out[3]: 0
-The statements defining a function arewritten only once, but may be called "to
do their job" from many points in a program and as often as you like.
-Calling square with a non-numeric argument like 'hello' causes a TypeError
because the exponentiation operator (**) works only with numeric values. ---------
CORRECT ANSWER-----------------The following code calls function square twice.
The first call produces the int value 49 and the second call produces the int value
0:
In [1]: def square(number):...: """Calculate the square of a number.""" ...: return
number ** 2 ...: In [2]: square(7)Out[2]: 49In [3]: square(.1)Out[3]: 0
Based on the following function definition:
def rectangle_area(length, width):"""Return a rectangle's area.""" return length *
width
The following call results in results in TypeError because the order of keyword
arguments matters—they need to match the corresponding parameters' positions
in the function definition:
rectangle_area(width=5, length=10) ---------CORRECT ANSWER-----------------False
,Which of the following statements is false?
-If randrange truly produces integers at random, every number in its range has an
equal probability (or chance or likelihood) of being returned each time we call it.
-We can use Python's underscore (_) digit separator to make a value like 3000000
more readable as 3_000_000.
-The expression range(6,000,000) would be incorrect. Commas separate
arguments in function calls, so Python would treat range(6,000,000) as a call to
range with the three arguments 6, 0 and 0.
-All of the above statements are true. ---------CORRECT ANSWER-----------------All of
the above statements are true.
What is the output of the following code:
min('yellow', 'red', 'orange', 'blue', 'green') ---------CORRECT ANSWER-----------------
blue
What does the following for statement print?
for counter in range(4): print(counter, end=' ') ---------CORRECT ANSWER-------------
----0 1 2 3
For variables x = 'a' and y = 'b', what will the following statement display:
print((x + y), 'and', (y + x)) ---------CORRECT ANSWER-----------------ab and ba
, Fill in the missing code to replace *** in the following code with a statement :
if grade >= 90:
***
so that will print a message like:'Congrats! Your grade of 91 is A '.
Your statement should print the value already entered and stored to a variable
grade = 91 ---------CORRECT ANSWER-----------------print('Congrats! Your grade of',
grade, 'is A')
Based on the following function definition that can receive an arbitrary number of
arguments:
In [1]: def average(*args):...: return sum(args) / len(args)...:
Which of the following statements is false? ---------CORRECT ANSWER-----------------
All of the above are true.
Fill in the missing code below to replace the ***
for ***:
print('$')
So that when you execute the code, it displays:
$
$
$
$ ---------CORRECT ANSWER-----------------in range(4)