Created
January 12, 2019 18:07
-
-
Save gerryjenkinslb/032b24024df0290c3c7a80b40f49b41f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# f-strings new in 3.6 and 3.7+ | |
# f-string tutorial code for video: https://youtu.be/c46t7eIldaI | |
# multiple columns how do you align decimals (zeros should fill in) | |
# using field width to align columns of numbers | |
values = [1, 3, 5, 7, 10, 21] | |
# table of float(v1/v2) for all combinations | |
print(f'{"n/d":>8s}', end='') # print string in "" with right aling code >8s | |
for denominator in values: # print headings for columns | |
print(f'{denominator:8d}', end='') | |
print() | |
for numerator in values: # for each row | |
print(f'{numerator:8d}', end='') | |
for denominator in values: # print n/d for each column | |
x = numerator / denominator | |
print(f'{x:8.4f}', end='') | |
print() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment