0

我是 python 新手,有没有办法修改这个代码,我可以用键盘输入电影和他们的评分,并将它附加到表中的行?

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
4

1 回答 1

0

我只是做了一些变量来将输入数据包含为一个元组。我没有在我的电脑上加载漂亮的表格,但我假设你应该能够输入一个包含每一行数据的变量。

我希望这会有所帮助,并且不会激怒任何人,因为我将其发布为答案,因为我觉得评论太长了。

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)
于 2015-01-30T06:14:41.710 回答