LearnFrenzy
Sign in Take a free test

Python Basics and Syntax · Predict the Output · Question 9

f-string with a format spec Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 9 Back to Exercise

What is the output of the following Python program?

main.py
name = "Asha"
marks = 91.456
print(f"{name} scored {marks:.1f}")
print(f"{name!r:>8}|")
  • A Asha scored 91.5 'Asha'| Correct
  • B Asha scored 91.4 'Asha'|
  • C Asha scored 91.5 Asha|
  • D Asha scored 91.456 'Asha' |
Correct Answer: Option A

.1f rounds to one decimal (91.5). !r uses repr(), which adds quotes, and >8 right-aligns the 6-character result in 8 places.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links