Home > Enterprise >  Output list data in one line
Output list data in one line

Time:02-21

the problem is that i cannot output all the data in one line, lettergrade(float(mylist[2])) and even a simple string like "hello" is always on the next line

lettergrade is just a simple function that returns a string

print("Student Name\t\tFinal Grade\t\tLetter Grade")
mylist = indata.split(",")
print(mylist[0]   " "   mylist[1]   "\t\t"   mylist[2]   "\t\t"   lettergrade(float(mylist[2])))

mylist looks like

['Johnson', 'Abby', '95.6\n']
['Smith', 'Frank', '91.3\n']
['Carson', 'Jack', '89.1\n']
['Wells', 'Orson', '87.9\n']

Output I get

Student Name            Final Grade             Letter Grade
Johnson Abby            95.6
                A
Smith Frank             91.3
                A
Carson Jack             89.1
                B

Expected output

Student Name            Final Grade             Letter Grade
Johnson Abby            95.6                    A
Smith Frank             91.3                    A           
Carson Jack             89.1                    B

CodePudding user response:

\n stands for a line break, you should remove it:

mylist = indata.replace('\n', '').split(",")

CodePudding user response:

You should remove the \n from the list :

['Johnson', 'Abby', '95.6']
['Smith', 'Frank', '91.3']
['Carson', 'Jack', '89.1']
['Wells', 'Orson', '87.9']
  • Related