I am confused about the output of my code.
This is my file:
201707001 Jenson_
201707002 Richard
201707003 Jean
This is my code:
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)
This is my output of the code
Please enter id: 201707001
Student found!
Student ID: 201707001
Student Name: Jenson
The student does not exist
The student does not exist
How do I fix my code?
Aucun commentaire:
Enregistrer un commentaire