PIXELBANKv8.2.1
Menu

String Formatter

Problem Statement

Format strings using f-strings and string methods.

Background

Python offers multiple ways to format strings:

  • f-strings: f"Hello {name}"
  • .format(): "Hello {}".format(name)
  • String methods: .upper(), .lower(), .title(), .strip()

Your Task

Write a function format_info(name, age, score) that returns a formatted info card.

Output Format

Return a dictionary with:

  • "greeting": "Hello, {name}!" (name in title case)
  • "info": "{name} is {age} years old"
  • "score_display": "Score: {score:.2f}" (2 decimal places)

Example:

Input:
name = "john doe", age = 25, score = 95.5
Output:
{'greeting': 'Hello, John Doe!', 'info': 'John Doe is 25 years old', 'score_display': 'Score: 95.50'}
Reasoning:

.title() capitalizes 'john doe' to 'John Doe', :.2f formats float to 2 decimals

Constraints:

  • Use f-strings or .format()
  • Apply .title() for proper name capitalization
Editor

Test Results

0/0
Run code to see test results.