0

I'm new to python, is there a way to modify this code to the point I can keyboard input movies and their rating and it appends to the row in the table?

from prettytable import PrettyTable

x = PrettyTable(["Moive Title", "Ratings"])
x.padding_width = 1 # One space between column edges and contents (default)
x.add_row(["Inception", "5 Stars"])
x.add_row(["Training Day","5 Stars"])
x.add_row(["Boyhood", "3 Stars"])
x.add_row(["Interstellar", "4.5 Stars"])

print x
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
dmb
  • 35
  • 1
  • 1
  • 3
  • 1
    I'm not familiar with pretty table but what's stopping you from doing something like: x.add_row([raw_input(), raw_input()]) – oxrock Jan 30 '15 at 03:21
  • @oxrock thank you so much!!!, never would have thought it was so easy – dmb Jan 30 '15 at 03:31

1 Answers1

0

I just made some variables to contain the input data as a tuple. I didn't load pretty table on my pc but I assume you should be able to enter a variable containing your data for each row.

I hope this helps and doesn't piss anyone off that I posted this as an answer as I felt it was too long for the comments.

import PrettyTable

firstRow = input ('What would you like to put in your first row sir?')
secondRow = input ('What would you like to put in your second row sir?')
thirdRow = input ('What would you like to put in your third row sir?')
fourthRow = input ('What would you like to put in your fourth row sir?')

x = PrettyTable(["Moive Title", "Ratings"])
x.padding_width = 1 # One space between column edges and contents (default)
x.add_row([firstRow])
x.add_row([secondRow])
x.add_row([thirdRow])
x.add_row([fourthRow])
print (x)
Patrick Falvey
  • 377
  • 1
  • 6