python - Using .format() to line up strings -


i need asterix lines lineup using .format() function. far can them move away titles on same line. need first asterix each string line up. sorry noob question.

index = 0 choice_titles = ['steal:','deal:','comp steal:','comp deal:'] choice_counts = [3, 7, 4, 6]  print('game stats: \n')  while index < len(choice_counts):     (format(choice_titles[index], '<10s'))     print(choice_titles[index], end='  ' )      asterix_disp = ''.join('*' number in range(0, choice_counts[index]))     (format(asterix_disp, '>10s'))     print(asterix_disp)      index += 1 

in order them line up, need make sure titles printed same length. 'comp steal:' 11 characters long, format should @ least much, 10 not enough. make @ least 12 or so.

furthermore, format() returns string formatted specification. don't it. guess wanted print it.

print(format(choice_titles[index], '12s'), end='  ') 

you don't need format asterisks since they're @ end. won't throw off alignment on else. print out. p.s., repeat character n times, multiply character n. have there unnecessarily complicated.

print('*' * choice_counts[index]) 

Comments