2

I'm having some trouble with this code not working correctly:

class Student:

def __init__(self, full_name, grade_level, grade_1, grade_2, grade_3):
    self.name = full_name
    self.gl = grade_level
    self.grade_1 = grade_1
    self.grade_2 = grade_2
    self.grade_3 = grade_3

def find_counselor(self, full_name):
    fname = list(self.name)
    for i in range(len(fname)):
        print(i)
        if fname[i] == " ":
            if fname[i+1] == "A" or "B" or "C" or "D" or "E" or "F" or "G":
                print(full_name, "'s counselor is Camille Nix.")
            elif fname[i+1] == "H" or "I" or "J" or "K" or "L" or "M" or "N" or "O" or "P":
                print(full_name, "'s counselor is Gay Myrick.")
            elif fname[i+1] == "Q" or "R" or "S" or "T" or "U" or "V" or "W" or "X" or "Y" or "Z":
                print(full_name, "'s counselor is Kerri Curcoe.")

person = Student
person("Bill Taylor", "Sophomore", 99, 99, 99).find_counselor("Bill Taylor")

The first letter of the last name of the student should determine which counselor the student goes to, but no matter what I enter as the name for the student it always returns to me as Camille Nix. I'm not sure why this is happening. Any help is much appreciated.

Dino Crammer
  • 53
  • 1
  • 3
  • 1
    `fname[i+1] == "A" or "B"` will always be true no matter what. you need to write conditions on either side. `fname[i+1] == "A" or fname[i+1] == "B"`. Also, you can do membership checks instead to simplify your condition. `if fname[i+1] in 'ABCDEFG' ` – Paritosh Singh Dec 15 '18 at 23:17
  • In addition what @ParitoshSingh wrote: Instead of looping through the name, you could also split the name and then just use the first latter of the second part. – Cleb Dec 15 '18 at 23:19

0 Answers0