Как мне найти csv-файл и получить правильный отступ, чтобы это работало
import csv #assuming the file is in csv format, import csv #Task: Search for a teacher, and return the subject they teach """File contents Mr A : Maths Mr B: History Mr C: Computing """ def main(): #open the file with open("teacherbook1.csv", "r") as teacherfile: teacher=input("Enter teacher you are looking for:") teacherfileReader=csv.reader(teacherfile) for row in teacherfileReader: for field in row: if field==teacher: print(row[1]) break else: main() main()
Что я уже пробовал:
Почти работает..
ток на выходе:
Enter teacher you are looking for:Mr A Philosophy Enter teacher you are looking for:Mr B Enter teacher you are looking for:Mr C Enter teacher you are looking for:Mr X Enter teacher you are looking for: