morep219
morep219

Reputation: 41

Output list data in one line

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

Upvotes: 0

Views: 57

Answers (2)

Cubix48
Cubix48

Reputation: 2681

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

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

Upvotes: 1

Achraf
Achraf

Reputation: 109

You should remove the \n from the list :

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

Upvotes: 1

Related Questions