How to align string statements | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 2

How to align string statements

school excersise asks us to print off total amounts, but I'm trying to align all totals underneath eachother. anyone's help is appreciated

3rd Sep 2017, 12:51 AM
michael
3 Respostas
+ 6
you can use format.
3rd Sep 2017, 1:12 AM
šŸ‘‘ Prometheus šŸ‡øšŸ‡¬
šŸ‘‘ Prometheus šŸ‡øšŸ‡¬ - avatar
+ 6
Thanks for attaching Python documentation. I haven't done formatting in 4 months so I am rusty
3rd Sep 2017, 1:16 AM
šŸ‘‘ Prometheus šŸ‡øšŸ‡¬
šŸ‘‘ Prometheus šŸ‡øšŸ‡¬ - avatar
+ 5
Using the format function for strings ... lower = [70, 79, 88, 97, 106] upper = [78, 87, 105, 114, 123] num = [5, 3, 4, 2, 6, 4] for l, u, n in zip(lower, upper, num): print('{0:>8} {1}'.format('{0}-{1}:'.format(l, u), '*' * n)) https://docs.python.org/3/library/string.html#format-specification-mini-language
3rd Sep 2017, 1:13 AM
t. Alberto Barbosa
t. Alberto Barbosa - avatar