如何原始输入到字典
How to raw input to dictionary
我是 python 的新手,有没有办法修改此代码,使我可以通过键盘输入电影及其评分并将其附加到 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
我刚刚制作了一些变量以将输入数据包含为元组。我没有在我的电脑上加载漂亮 table,但我认为你应该能够输入一个包含每一行数据的变量。
我希望这对我有所帮助并且不会激怒任何人,因为我觉得它对评论来说太长了。
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)
我是 python 的新手,有没有办法修改此代码,使我可以通过键盘输入电影及其评分并将其附加到 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
我刚刚制作了一些变量以将输入数据包含为元组。我没有在我的电脑上加载漂亮 table,但我认为你应该能够输入一个包含每一行数据的变量。
我希望这对我有所帮助并且不会激怒任何人,因为我觉得它对评论来说太长了。
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)