如何将输入原始输入到字典中

时间:2015-01-30 03:15:58

标签: python append raw-input prettytable

我是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

1 个答案:

答案 0 :(得分: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)