【发布时间】:2018-01-27 14:31:30
【问题描述】:
我对代码的输出感到困惑。
这是我的文件:
201707001 Jenson_
201707002 Richard
201707003 Jean
这是我的代码:
def studentInfo (userInput): # storing student info
# read the students file
with open('C:\\Users\\jaspe\\Desktop\\PADS Assignment\\Student.txt') as f:
for line in f:
stdId, stdName = line.strip().split(" ", 1)
# check if the student exist
if userInput == stdId:
print("Student found!")
print("Student ID: " + stdId + "\nStudent Name: " + stdName)
else:
print("The student does not exist")
studentFinder = input("Please enter id: ")
studentInfo(studentFinder)
这是我的代码输出
Please enter id: 201707001
Student found!
Student ID: 201707001
Student Name: Jenson
The student does not exist
The student does not exist
如何修复我的代码?
【问题讨论】:
标签: python if-statement text with-statement