計算機科学のブログ

ほしい物リスト

Python - Formatted String Literals: Make Charts from Data - f-string 1

Head First Python: A Learner’s Guide to the Fundamentals of Python Programming, A Brain-Friendly GuidePaul Barry(著)、 O’Reilly Mediaの Chapter 5.(Formatted String Literals: Make Charts from Data)、EXERCISE(261/682)の解答を求めてみる。

Jupyter(コード、入出力結果)

Charts.ipynb

title = f'{swimmer} (Under {age}) {distance} {stroke}'
html = f'<html><head><title>{title}</title>'
html += f'</title></head><body><h3>{title}</h3>'
print(html)
<html><head><title>Darius (Under 13) 100m Fly</title></title></head><body><h3>Darius (Under 13) 100m Fly</h3>