0

I am trying to create a simple table using the PrettyTable Packet in Python 3. However, whenever I complete typing the samples, the sentence (SyntaxError: multiple statements found while compiling a single statement) always appear after I press enter. May anyone explain what's wrong with the code? I'll attach the code I use below. Thank you so much!

from prettytable import PrettyTable
#Add Columns
Table=PrettyTable(["Name","District","Contact Number","Job"])
#Add Rows
Table.add_row(["John","Trincomalee","0752020117","Doctor"])
Table.add_row(["Michael","Colombo","0761709896","Lawyer"])
Table.add_row(["Nick","Jaffna","0772643635","Teacher"])
Table.add_row(["Gibbs","Batticalo","0752114101","Engineer"])
#Display the Table
print(Table)

1 Answers1

0
from prettytable import PrettyTable

columns = ["Student Name", "Class", "Contact Number", "Job"]

myTable = PrettyTable()

# Add Columns
myTable.add_column(columns[0], ["Student Name", "Trincomalee", "Michael", "Nick", "Gibbs"]
myTable.add_column(columns[1], ["Trincomalee", "Colombo", "Jaffna", "Batticalo"])
myTable.add_column(columns[2], ["0752020117", "0761709896", "0772643635", "0772643635"])
myTable.add_column(columns[3], ["Doctor", "Lawyer", "Teacher", "Engineer"])

Try this

bdeviOS
  • 449
  • 1
  • 6