Challenge: Custom Output Formatting
In many real-world scenarios, you need to present data in a way that's both readable and visually organized, such as generating reports, displaying high scores, or logging events. Mastering custom output formatting with strings is essential for producing professional, clear output that aligns information in columns, making it easy to scan and interpret. You will now apply your string formatting skills to a practical scenario: aligning names and scores in a columnar format. This exercise will reinforce your understanding of alignment options and help you create output that's both attractive and functional.
Swipe to start coding
Write a function that takes a list of tuples, where each tuple contains a name and a score. Return a single string in which each name is left-aligned and each score is right-aligned in columns. The width of the name and score columns should be determined by the longest name and the highest score, respectively. Each name and score should be separated by a single space. Each name-score pair should appear on its own line in the returned string.
Solution
Thanks for your feedback!
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 6.67
Challenge: Custom Output Formatting
Swipe to show menu
In many real-world scenarios, you need to present data in a way that's both readable and visually organized, such as generating reports, displaying high scores, or logging events. Mastering custom output formatting with strings is essential for producing professional, clear output that aligns information in columns, making it easy to scan and interpret. You will now apply your string formatting skills to a practical scenario: aligning names and scores in a columnar format. This exercise will reinforce your understanding of alignment options and help you create output that's both attractive and functional.
Swipe to start coding
Write a function that takes a list of tuples, where each tuple contains a name and a score. Return a single string in which each name is left-aligned and each score is right-aligned in columns. The width of the name and score columns should be determined by the longest name and the highest score, respectively. Each name and score should be separated by a single space. Each name-score pair should appear on its own line in the returned string.
Solution
Thanks for your feedback!
single