-1

My code is only inputting one print command when there are two that need to be put out. I know this problem is simple but I need a new perspective here is my code:

name = input("What is your name? \n")
h1 = ("Class Name")
h2 = ("Class Grade")
h3 = ("Credit Hours")
point = input("\nEnter your class name followed by your letter grade and hours (say Done to stop input):\n")
class_data = []
while point != "Done":
    words = point.split(" ")
    if len(words) == 1:
        print("Error: No spaces in string. Try again.")
    elif len(words) > 4:
        print("Error: Too many spaces in input. Try again. ")
    else:
        try:
            class_name = words[0]
            grades = (words[1])
            hrs = int(words[2])
            print("Name of class:", class_name)
            print("Grade:", grades)
            print("Class Hours:", hrs)
            class_data.append((class_name, grades, hrs,))
        except ValueError:
            print("Error: Space not followed by an integer.")
    point = input("\nEnter your class name followed by your letter grade and hours (say Done to stop input):\n")

    def gpa_calculator(grades):
        points = 0
        i = 0
        grade_c = {"A":4,"A-":3.67,"B+":3.33,"B":3.0,"B-":2.67, "C+":2.33,"C":2.0,"C-":1.67,"D+":1.33,"D":1.0,"F":0}
        if grades != class_data:
            for grade in grades:
                points += grade_c[item[1]]
            gpa = points / len(class_data)
            return gpa
        else:
            return None 

print("Name: ", name)
print("-" * 66)
print("%-17s|%13s|%7s|" % (h1, h2, h3))
print("-" * 66)
for item in class_data:
    print("%-17s|%13s|%12s|" % (item[0], item[1], item[2]))
print("-" * 66)
print('Your projected GPA is: ',(gpa_calculator(grades)))
print("-" * 66)
if item[0] == "Computer-Science" and item[1] == "D":
    print ("failing CS")
if item[0] == "Programming" and item[1] == "D":
    print ("failing programming")

what i need help with are the last four lines output:

What is your name? 
Nich

Enter your class name followed by your letter grade and hours (say Done to stop input):
Programming D 10
Name of class: Programming
Grade: D
Class Hours: 10

Enter your class name followed by your letter grade and hours (say Done to stop input):
Computer-Science D 10
Name of class: Computer-Science
Grade: D
Class Hours: 10

Enter your class name followed by your letter grade and hours (say Done to stop input):
Done
Name:  Nich
------------------------------------------------------------------
Class Name     |Class Grade|Credit Hours|
------------------------------------------------------------------
Programming    |          D|          10|
Computer-Science|          D|          10|
------------------------------------------------------------------
Your projected GPA is:  0.5
------------------------------------------------------------------
failing CS

I've tried elif and true commands this is the closest I've been to solving this.

Barmar
  • 741,623
  • 53
  • 500
  • 612
Grimmo
  • 1
  • 2

1 Answers1

0

You need another loop, like the one you used to print the grade table.

for item in class_data:
    if item[1] in ("D", "F"):
        print(f"failing {item[0]}")
Barmar
  • 741,623
  • 53
  • 500
  • 612