URGENT NEED HELP Hello! I am using python to program this. How do I fix the proper alignment for the output? so that no matter what I enter, it is equally aligned. Is there a way I can do that without using the tabular module? the expected output is shown below Here is my current code ------------------------------------------------------- def SPACES_COUNTER (name): name counter_len = 0 name_len = [] while (counter_len < len(name)): for i in range (counter_len): name_len.append(len(name[i])) counter_len += 1 return min(name_len, default=0) stud_id = [] name = [] address = [] age = [] physicsMarks = [] cMarks = [] mathMarks = [] averageMarks = [] num_of_records = int(input("Enter number of records: ")) counter=0 while (counter< num_of_records): for i in range(num_of_records): stud_id_input = input("Enter Student ID: ") stud_id.append(stud_id_input) name_input = input('Enter Name: ') name.append(name_input) address_input = input('Enter address: ') address.append(address_input) age_input = int(input("Enter Age: ")) age.append(age_input) physics_marks = int(input("Enter Physics marks in 1st semester: ")) physicsMarks.append(physics_marks) c_marks = int(input("Enter C marks in 1st semester: ")) cMarks.append(c_marks) math_marks = int(input("Enter Math marks in 1st semester: ")) mathMarks.append(math_marks) average_marks = float((physics_marks + c_marks + math_marks)/3) averageMarks.append(average_marks) counter += 1 name_spaces = SPACES_COUNTER(name) student_spaces = SPACES_COUNTER(stud_id) address_spaces = SPACES_COUNTER(address) counter_disp = 0 while (counter_disp < num_of_records): print("Student ID "+' '* (student_spaces-8) +"Name"+' ' * (name_spaces-1) + "Address" +' ' * (address_spaces - 7)+' '+ "Age"+' '+ "Physics Grade"+' '+ "C Grade"+' '+ "Math Grade"+' '+ "Average Grade") for i in range (num_of_records): print(stud_id[i],' ' *(student_spaces - len(stud_id[i])+1),'', name[i],''*(name_spaces-len(name[i])+1), '', address[i],' '*(address_spaces - len(address[i])),' ', age[i],' ', physicsMarks[i],' \t\t', cMarks[i],' \t', mathMarks[i],' \t', "{:.2f}".format(averageMarks[i])) counter_disp += 1
URGENT NEED HELP
Hello! I am using python to program this. How do I fix the proper alignment for the output? so that no matter what I enter, it is equally aligned. Is there a way I can do that without using the tabular module?
the expected output is shown below
Here is my current code
-------------------------------------------------------
def SPACES_COUNTER (name):
name
counter_len = 0
name_len = []
while (counter_len < len(name)):
for i in range (counter_len):
name_len.append(len(name[i]))
counter_len += 1
return min(name_len, default=0)
stud_id = []
name = []
address = []
age = []
physicsMarks = []
cMarks = []
mathMarks = []
averageMarks = []
num_of_records = int(input("Enter number of records: "))
counter=0
while (counter< num_of_records):
for i in range(num_of_records):
stud_id_input = input("Enter Student ID: ")
stud_id.append(stud_id_input)
name_input = input('Enter Name: ')
name.append(name_input)
address_input = input('Enter address: ')
address.append(address_input)
age_input = int(input("Enter Age: "))
age.append(age_input)
physics_marks = int(input("Enter Physics marks in 1st semester: "))
physicsMarks.append(physics_marks)
c_marks = int(input("Enter C marks in 1st semester: "))
cMarks.append(c_marks)
math_marks = int(input("Enter Math marks in 1st semester: "))
mathMarks.append(math_marks)
average_marks = float((physics_marks + c_marks + math_marks)/3)
averageMarks.append(average_marks)
counter += 1
name_spaces = SPACES_COUNTER(name)
student_spaces = SPACES_COUNTER(stud_id)
address_spaces = SPACES_COUNTER(address)
counter_disp = 0
while (counter_disp < num_of_records):
print("Student ID "+' '* (student_spaces-8) +"Name"+' ' * (name_spaces-1) + "Address" +' ' * (address_spaces - 7)+' '+ "Age"+' '+ "Physics Grade"+' '+ "C Grade"+' '+ "Math Grade"+' '+ "Average Grade")
for i in range (num_of_records):
print(stud_id[i],' ' *(student_spaces - len(stud_id[i])+1),'', name[i],''*(name_spaces-len(name[i])+1), '', address[i],' '*(address_spaces - len(address[i])),' ', age[i],' ', physicsMarks[i],' \t\t', cMarks[i],' \t', mathMarks[i],' \t', "{:.2f}".format(averageMarks[i]))
counter_disp += 1
Step by step
Solved in 2 steps with 2 images