将文件中的名称分配给索引

时间:2018-11-10 12:05:56

标签: python-3.x

我正在用python开发顶级王牌游戏,我需要一些帮助。 我需要将txt文件中的名称分配给索引,但要分配用户指定的数量。

def game():
cards = input("How many cards do you want to play with? (answer must be greater than 4, less than 30 and even \n")
cards = int(cards)
if cards % 2 != 0:
    print("Error, answer must be even")
    print(cards % 2)
    menu()
if cards < 4 or cards > 30:
    print("Error, answer must be greater than 4 and less than 30")
    menu()
with open("dogs.txt","r") as f:

这是代码,但是打开文件后我想不出要放什么,如果有人可以帮助我,将不胜感激。

1 个答案:

答案 0 :(得分:0)

只需尝试使用read()readline()函数,例如:

f.readline()