如何获取特定ord中的文件

2024-04-25 00:18:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我在做一个学校作业,我们要做一个塔玛戈奇。现在,我有一个文本文件的问题,其中的食物为塔玛戈奇保存。我得按字母顺序和字长排列那个文件。这样地。你知道吗

This is how the words should display (the words are in Dutch). The g and o are later added to the file and have to stay behind the word’s.

该计划还增加了新的食物名单,然后它必须在正确的顺序再次。 这是我已经做的。你知道吗

def voeding_toevoegen():
file = open('voeding.txt', 'a')
toe_te_voegen_voeding = (str(input('voer voeding in (bijvoorbeeld wortel, snickers, spitskool, etc.)\n')))
file.write(toe_te_voegen_voeding)
g_of_o(file, toe_te_voegen_voeding)

def g_of_o(file, toe_te_voegen_voeding):
gezond_ongezond = (str(input('is deze voeding gezond (g) of ongezond (o)?\n')))
if gezond_ongezond == 'g':
    file.write(':g\n')
    print('de voeding "'+ toe_te_voegen_voeding +'" is toegevoegd aan de lijst')
elif gezond_ongezond == 'o':
    file.write(':o\n')
    print('de voeding "'+ toe_te_voegen_voeding +'" is toegevoegd aan de lijst')
else:
    print('geen geldigen optie (kies een "g" of een "o"')
    g_of_o(file, toe_te_voegen_voeding)

file.close()


voeding_toevoegen()

然后它进入第二个函数,在那里它会问你刚放进去的食物是健康的(g)还是不健康的(o)。这就在文件里食物的后面。如果你不选择g或o,电脑会说它错了,然后再问这个问题。直到你纠正过来。然后说是印刷品(食物…)…。添加到文件中)。你知道吗

我希望你能理解这个节目。现在的问题是,如何按照特定的长度和字母顺序获取文件?你知道吗

我希望你能帮助我。你知道吗


Tags: 文件ofthe顺序isdefilewrite