如何读取其中包含流程图的.txt文件并在程序中使用它

时间:2018-10-18 18:14:35

标签: python-2.7

这是提示:

正确的程序将允许用户对任何问题回答是(y)或否(n),随后 到流程图中的适当路径。一旦达到结束状态,您的程序应终止。 您可以放心地假设我不会回答无效的问题(即不是y或n) 在测试时。

这是帮助我们解决的代码:

    ###########################################################################################
# Name: 
# Date: 
# Description: 
###########################################################################################
import sys

# processes/"plays" the flowchart
# *****this is the only part of the code that you should modify/add to*****
def play(entities):
    # pass is a reserved word that simply means "do nothing"
    # it is used when Python expects code in a block (e.g., a function) but none is provided at the time
    # it usually means that code will be provided at a later time
    pass

########
# MAIN #
########
# make sure that a flowchart file is specified at the command line
if (len(sys.argv) < 2):
    print "Usage: python {} <file>".format(sys.argv[0])
    exit(0)

# open the flowchart file, read it into a list, and close it
file = open(sys.argv[1], "r")
entities = []
for entity in file:
    entities.append(entity.rstrip())
file.close()

# "play" the flowchart
play(entities)

0 个答案:

没有答案