我對我的代碼輸出感到困惑。Python Open File - If Else Statement
這是我的文件:
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
我如何修復我的代碼?
你的問題還不清楚。你說「有什麼方法可以修復我的代碼」,但是你沒有說明代碼應該做什麼。請查看https://stackoverflow.com/help/how-to-ask – mtrw