我的问题是,在python首先读取原始输入后,它随后不再正确读取输入。我已经尝试了很多东西,但似乎无法理解。我究竟做错了什么?

file_path = 'C:\\Users\\Neo\\My Documents\\Python Scripts\\FTC Scouting\\sample.txt'
file = open(file_path, 'r')
Team_Numbers = []

tNum = 'Team Number: '
tName = 'Name: '
ui = ''

def list_teams(n):
    count = 0
    if n == '1':
        for line in file:
            check = line.find(tNum)
            if not check == -1:
                print line[len(tNum):]    #prints everything after the Team Number:
            count += 1

    elif n == 2:
        for line in file:
            check = line.find(tName)
            if not check == -1:
                print line[len(tName):]    #prints everything after the Team Number:
            count += 1

while not ui == 'end':

    ui = raw_input('1: to list Team Numbers\n2: to list Names\n')
    list_teams(ui)


file.close()

最佳答案

Python是强类型的。

elif n == '2':

10-07 19:17
查看更多