Skip to main content
 首页 » 编程设计

python 输入被读取错误

2025年05月04日13dflying

我的问题是,在 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':