logo
logo
AI Products 
Leaderboard Community🔥 Earn points

Adventures in Python: Using a Dictionary to Print a Table (OT: HP Prime new keyboard colors)

avatar
Ambrozy Gustosz
collect
0
collect
0
collect
0
Adventures in Python: Using a Dictionary to Print a Table (OT: HP Prime new keyboard colors)

Here is a short program where a dictionary and the format command are used to print a nice looking table.

In Python, a dictionary is defined as list of two-element entries, in the format { x1:y1, x2:y2, x3:y3, … }.

Where x1, y1, x2, y2, and so on are strings or numbers.

We can also designate the format of data within a print statement.

print( a string that contains {n:ABC}.format(n0, n1, n2, …))

B = length of a field in the form of L.N (L = length of the field, N = number of decimal places, note that L is the minimum filed length, not maximum)

collect
0
collect
0
collect
0
avatar
Ambrozy Gustosz