Help centering multiple string output | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Help centering multiple string output

So my question is how can I get the program to center the output when print(s) executes regardless of different character lengths of various inputs entered when running this program? ### Program for New Hire/Employee data HR department ### ### Cole_Orndoff ### ### January_27_2020 ### ###Comp_B10 Intro_to_Python### ###################### ###Input/ Employee Information /Input### nameFirst = (input("First Name: ")) nameLast = (input("Last Name: ")) empNum = (input("Employee ID: ")) empDepart = (input("Department: ")) hoursWeek = int(input("Hours/Week: ")) ###variables### x = (hoursWeek) y = (17.50) z = (x*y) ### Output f-String multi-line /Output### s = ('''EMPLOYEE DETAILS ----- NAME ----- {f} {l} ----- ID ----- {i} -----DEPARTMENT----- {d} -----WEEKLY PAY----- {p} ''').format(f=nameFirst,l=nameLast,i=empNum,d=empDepart,p=("

quot;+format(z, '.2f'))) print(s)

28th Jan 2021, 4:02 AM
Gutz_X_73vEn
Gutz_X_73vEn - avatar
4 Answers
28th Jan 2021, 4:15 AM
jtrh
jtrh - avatar
+ 2
'\n'.join('{:^80}'.format(ln) for ln in s.split('\n'))
28th Jan 2021, 4:15 AM
visph
visph - avatar
+ 1
thanks you^^!
28th Jan 2021, 7:04 AM
Gutz_X_73vEn
Gutz_X_73vEn - avatar
+ 1
i cant believe i couldnt figure that out when i was looking earlier XD
28th Jan 2021, 7:07 AM
Gutz_X_73vEn
Gutz_X_73vEn - avatar