350-401 · Question #1002
What does the statement print(format(0.8, '.0%')) display?
The correct answer is D. 80%. Explanation Option D (80%) is correct because Python's format() function with the '%' format specifier multiplies the value by 100 and appends a % sign, so 0.8 × 100 = 80. The .0 precision specifier removes any decimal places, giving a clean 80% output. Why the distractors are wr
Question
What does the statement print(format(0.8, '.0%')) display?
Options
- A8.8%
- B0.8%
- C8%
- D80%
How the community answered
(60 responses)- A2% (1)
- B2% (1)
- C3% (2)
- D93% (56)
Explanation
Explanation
Option D (80%) is correct because Python's format() function with the '%' format specifier multiplies the value by 100 and appends a % sign, so 0.8 × 100 = 80. The .0 precision specifier removes any decimal places, giving a clean 80% output.
Why the distractors are wrong:
- A (8.8%) is nonsensical - there's no mathematical operation that produces this from
0.8 - B (0.8%) is wrong because it incorrectly assumes the value is displayed as-is without the ×100 conversion
- C (8%) is wrong because it only moves the decimal one place instead of two (i.e., multiplying by 10 instead of 100)
Memory tip: Think of the % format specifier as doing the "percentage conversion for you" - just like converting 0.8 to a percentage in math means multiplying by 100. The .0 simply controls how many decimal places appear, so .0% means "convert to percent, show zero decimals."
Topics
Community Discussion
No community discussion yet for this question.