Expected Output: Enter number of records: 2 Enter Student ID: 1234567890 Enter Name: Jane Doe Enter address: New York City Enter Age: 23 Enter Physics marks in 1st semester: 90 Enter C marks in 1st semester: 98 Enter Math marks in 1st semester: 89 Enter Student ID: 0987654322 Enter Name: John Doe Enter address: Alexander City Enter Age: 24 Enter Physics marks in 1st semester: 89 Enter C marks in 1st semester: 90 Enter Math marks in 1st semester: 97 C Grade Physics Grade 90 Average Grade 92.33 Student ID Name Address Age 23 Math Grade 1234567890 Jane Doe New York City Alexander City 98 89 0987654322 John Doe 24 89 90 97 92.00
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
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 1 images