Python Program help with IF Else

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mdmytryk
    New Member
    • Sep 2007
    • 12

    Python Program help with IF Else

    Hey, im new to computer programming as well as python, so please be gentle. Im working on a program that will calculate grades. When a value other than A,B,C,D, or F is entered, i want the program to give an error message. This is what i have come up with:

    [CODE=python]
    print "welcome to the GPA calculator"

    totalpoints=0.0

    name=raw_input( "please enter the name of the student ")
    grade=raw_input ("please enter "+name+ "'s English grade ")

    if grade == "A" or "a":

    totalpoints = totalpoints + 4.0*3

    elif grade == "B "or "b":

    totalpoints = totalpoints + 3.0*3

    elif grade == "C" or "c":

    totalpoints = totalpoints + 2.0*3

    elif grade == "D" or "d":

    totalpoints = totalpoints + 1.0*3

    elif grade == "F" or "f":

    totalpoints = totalpoints + 0.0*3

    else:

    print "Imput is not correct"
    [/CODE]


    The when a value is entered that is not A...F, the "imput is not correct" does not display. Could somebody please tell me what i am doing wrong here? Thanks alot,
    mike
    Last edited by bartonc; Sep 13 '07, 10:21 PM. Reason: Added [CODE=python][/CODE] tags.
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    [CODE=python]
    if (grade == "A") or (garde == "a"):

    # or

    if grade in "Aa":

    # or

    if grade.lower() == 'a':

    # or

    if grade.upper() == 'A':
    #...
    print totalpoints[/CODE]

    Comment

    • mdmytryk
      New Member
      • Sep 2007
      • 12

      #3
      that was amazingly fast, i really appreciate the help.

      mike

      Comment

      • bartonc
        Recognized Expert Expert
        • Sep 2006
        • 6478

        #4
        Originally posted by mdmytryk
        that was amazingly fast, i really appreciate the help.

        mike
        Watch out! I was editing while you were reading...

        Comment

        • mdmytryk
          New Member
          • Sep 2007
          • 12

          #5
          How would i write code that would take me from the end of the code back to the beginning? I imagine this would have to be some kind of while loop, but i cant put my finger on how i would incorporate it into the existing code.

          EDIT

          nevermind, i jumped the gun asking for help, i think i figured it out.

          thanks

          Comment

          • bartonc
            Recognized Expert Expert
            • Sep 2006
            • 6478

            #6
            Originally posted by mdmytryk
            How would i write code that would take me from the end of the code back to the beginning? I imagine this would have to be some kind of while loop, but i cant put my finger on how i would incorporate it into the existing code.

            EDIT

            nevermind, i jumped the gun asking for help, i think i figured it out.

            thanks
            That's OK. Here are some ideas for you to play with:[CODE=python]
            print "welcome to the GPA calculator"


            ### some basic input checking:
            ##while True: # always repeat #
            ## nClasses = raw_input("plea se enter the number of classes for the student ")
            ## try:
            ## nGrades = int(nClasses) # try to convert to an integer
            ## break # break out of the loop
            ## except ValueError: # couldn't convert
            ## pass # do nothing

            # start with a list of classes #
            ClassNames = ('English', 'Math', 'History')
            nClasses = len(ClassNames)
            Grades = tuple("ABCDF")

            # get the student's name
            name = raw_input("plea se enter the name of the student ")

            totalpoints=0.0

            # Now, loop on the 'Classes' list - actaully a tuple of names
            for className in ClassNames:
            grade = None
            while grade not in Grades:
            # we'll use string formatting instead of addition
            # variables are plugged into the '%s' locations #
            grade = raw_input("plea se enter %s's %s grade " %(name, className))
            grade = grade.upper()

            if grade == "A":
            totalpoints = totalpoints + 4.0

            elif grade == "B":
            totalpoints = totalpoints + 3.0

            elif grade == "C":
            totalpoints = totalpoints + 2.0

            elif grade == "D":
            totalpoints = totalpoints + 1.0

            ## no need to add zero
            ## elif grade == "F":
            ## totalpoints = totalpoints + 0.0

            print "The GPA is %.1f" %(totalpoints/nClasses)[/CODE]

            Comment

            • mdmytryk
              New Member
              • Sep 2007
              • 12

              #7
              I finished writing the program i was working on and was wondering if i could get some feedback on it. This was an assignment for a class, so some of the values were set by the professor, such as the number of classes, the lame greetings, etc. As far as i know, the program works, although im not sure how orthodox my coding is.
              [CODE=python]
              student=0
              while student==0:

              print "welcome to Mike's GPA calculator!"

              name=raw_input( "please enter the name of the student: ")
              totalpoints=0.0
              count=0
              while count==0:

              grade=raw_input ("please enter "+name+ "'s English grade: ")

              if (grade == "A") or (grade == "a"):
              totalpoints = totalpoints + 4.0*3
              count = 1
              elif (grade == "B") or (grade == "b"):
              totalpoints = totalpoints + 3.0*3
              count = 1
              elif (grade == "C") or (grade == "c"):
              totalpoints = totalpoints + 2.0*3
              count = 1
              elif (grade == "D") or (grade == "d"):
              totalpoints = totalpoints + 1.0*3
              count = 1
              elif (grade == "F") or (grade == "f"):
              totalpoints = totalpoints + 0.0*3
              count =1
              else:
              print "The input you have entered is not valid"
              count = 0

              count=0
              while count==0:

              grade=raw_input ("please enter "+name+ "'s Math grade: ")

              if (grade == "A") or (grade == "a"):
              totalpoints = totalpoints + 4.0*3
              count = 1
              elif (grade == "B") or (grade == "b"):
              totalpoints = totalpoints + 3.0*3
              count = 1
              elif (grade == "C") or (grade == "c"):
              totalpoints = totalpoints + 2.0*3
              count = 1
              elif (grade == "D") or (grade == "d"):
              totalpoints = totalpoints + 1.0*3
              count = 1
              elif (grade == "F") or (grade == "f"):
              totalpoints = totalpoints + 0.0*3
              count =1
              else:
              print "The input you have entered is not valid"
              count = 0
              count=0
              while count==0:

              grade=raw_input ("please enter "+name+ "'s Chemistry grade: ")

              if (grade == "A") or (grade == "a"):
              totalpoints = totalpoints + 4.0*2
              count = 1
              elif (grade == "B") or (grade == "b"):
              totalpoints = totalpoints + 3.0*2
              count = 1
              elif (grade == "C") or (grade == "c"):
              totalpoints = totalpoints + 2.0*2
              count = 1
              elif (grade == "D") or (grade == "d"):
              totalpoints = totalpoints + 1.0*2
              count = 1
              elif (grade == "F") or (grade == "f"):
              totalpoints = totalpoints + 0.0*2
              count =1
              else:
              print "The input you have entered is not valid"
              count = 0
              count=0
              while count==0:

              grade=raw_input ("please enter "+name+ "'s Physics grade: ")

              if (grade == "A") or (grade == "a"):
              totalpoints = totalpoints + 4.0*2
              count = 1
              elif (grade == "B") or (grade == "b"):
              totalpoints = totalpoints + 3.0*2
              count = 1
              elif (grade == "C") or (grade == "c"):
              totalpoints = totalpoints + 2.0*2
              count = 1
              elif (grade == "D") or (grade == "d"):
              totalpoints = totalpoints + 1.0*2
              count = 1
              elif (grade == "F") or (grade == "f"):
              totalpoints = totalpoints + 0.0*2
              count =1
              else:
              print "The input you have entered is not valid"
              count = 0

              totalpoints = totalpoints/10
              print "The gpa for "+name+" is",totalpoin ts


              ask=raw_input(" would you like to calculate another GPA?: y/n:" )

              if (ask == "y") or (ask == "Y"):
              student=0
              else:
              student=1

              raw_input("\n\n Thank you for using Mike's GPA calculator. Please press Enter to Exit.")[/CODE]
              Last edited by bartonc; Sep 15 '07, 04:53 AM. Reason: Added [CODE=python][/CODE] tags.

              Comment

              • ilikepython
                Recognized Expert Contributor
                • Feb 2007
                • 844

                #8
                Originally posted by mdmytryk
                I finished writing the program i was working on and was wondering if i could get some feedback on it. This was an assignment for a class, so some of the values were set by the professor, such as the number of classes, the lame greetings, etc. As far as i know, the program works, although im not sure how orthodox my coding is.

                student=0
                while student==0:

                print "welcome to Mike's GPA calculator!"

                name=raw_input( "please enter the name of the student: ")
                totalpoints=0.0
                count=0
                while count==0:

                grade=raw_input ("please enter "+name+ "'s English grade: ")

                if (grade == "A") or (grade == "a"):
                totalpoints = totalpoints + 4.0*3
                count = 1
                elif (grade == "B") or (grade == "b"):
                totalpoints = totalpoints + 3.0*3
                count = 1
                elif (grade == "C") or (grade == "c"):
                totalpoints = totalpoints + 2.0*3
                count = 1
                elif (grade == "D") or (grade == "d"):
                totalpoints = totalpoints + 1.0*3
                count = 1
                elif (grade == "F") or (grade == "f"):
                totalpoints = totalpoints + 0.0*3
                count =1
                else:
                print "The input you have entered is not valid"
                count = 0

                count=0
                while count==0:

                grade=raw_input ("please enter "+name+ "'s Math grade: ")

                if (grade == "A") or (grade == "a"):
                totalpoints = totalpoints + 4.0*3
                count = 1
                elif (grade == "B") or (grade == "b"):
                totalpoints = totalpoints + 3.0*3
                count = 1
                elif (grade == "C") or (grade == "c"):
                totalpoints = totalpoints + 2.0*3
                count = 1
                elif (grade == "D") or (grade == "d"):
                totalpoints = totalpoints + 1.0*3
                count = 1
                elif (grade == "F") or (grade == "f"):
                totalpoints = totalpoints + 0.0*3
                count =1
                else:
                print "The input you have entered is not valid"
                count = 0
                count=0
                while count==0:

                grade=raw_input ("please enter "+name+ "'s Chemistry grade: ")

                if (grade == "A") or (grade == "a"):
                totalpoints = totalpoints + 4.0*2
                count = 1
                elif (grade == "B") or (grade == "b"):
                totalpoints = totalpoints + 3.0*2
                count = 1
                elif (grade == "C") or (grade == "c"):
                totalpoints = totalpoints + 2.0*2
                count = 1
                elif (grade == "D") or (grade == "d"):
                totalpoints = totalpoints + 1.0*2
                count = 1
                elif (grade == "F") or (grade == "f"):
                totalpoints = totalpoints + 0.0*2
                count =1
                else:
                print "The input you have entered is not valid"
                count = 0
                count=0
                while count==0:

                grade=raw_input ("please enter "+name+ "'s Physics grade: ")

                if (grade == "A") or (grade == "a"):
                totalpoints = totalpoints + 4.0*2
                count = 1
                elif (grade == "B") or (grade == "b"):
                totalpoints = totalpoints + 3.0*2
                count = 1
                elif (grade == "C") or (grade == "c"):
                totalpoints = totalpoints + 2.0*2
                count = 1
                elif (grade == "D") or (grade == "d"):
                totalpoints = totalpoints + 1.0*2
                count = 1
                elif (grade == "F") or (grade == "f"):
                totalpoints = totalpoints + 0.0*2
                count =1
                else:
                print "The input you have entered is not valid"
                count = 0

                totalpoints = totalpoints/10
                print "The gpa for "+name+" is",totalpoin ts


                ask=raw_input(" would you like to calculate another GPA?: y/n:" )

                if (ask == "y") or (ask == "Y"):
                student=0
                else:
                student=1

                raw_input("\n\n Thank you for using Mike's GPA calculator. Please press Enter to Exit.")
                Use:
                [code=python]
                if ask.lower() == "y":
                ... ...
                [/code]
                instead of
                [code=python]
                if (ask == "Y") or (ask == "y"):
                ... ...
                [/code]
                Haven't checked it thouroughly though.

                Comment

                • ilikepython
                  Recognized Expert Contributor
                  • Feb 2007
                  • 844

                  #9
                  Originally posted by mdmytryk
                  I finished writing the program i was working on and was wondering if i could get some feedback on it. This was an assignment for a class, so some of the values were set by the professor, such as the number of classes, the lame greetings, etc. As far as i know, the program works, although im not sure how orthodox my coding is.

                  student=0
                  while student==0:

                  print "welcome to Mike's GPA calculator!"

                  name=raw_input( "please enter the name of the student: ")
                  totalpoints=0.0
                  count=0
                  while count==0:

                  grade=raw_input ("please enter "+name+ "'s English grade: ")

                  if (grade == "A") or (grade == "a"):
                  totalpoints = totalpoints + 4.0*3
                  count = 1
                  elif (grade == "B") or (grade == "b"):
                  totalpoints = totalpoints + 3.0*3
                  count = 1
                  elif (grade == "C") or (grade == "c"):
                  totalpoints = totalpoints + 2.0*3
                  count = 1
                  elif (grade == "D") or (grade == "d"):
                  totalpoints = totalpoints + 1.0*3
                  count = 1
                  elif (grade == "F") or (grade == "f"):
                  totalpoints = totalpoints + 0.0*3
                  count =1
                  else:
                  print "The input you have entered is not valid"
                  count = 0

                  count=0
                  while count==0:

                  grade=raw_input ("please enter "+name+ "'s Math grade: ")

                  if (grade == "A") or (grade == "a"):
                  totalpoints = totalpoints + 4.0*3
                  count = 1
                  elif (grade == "B") or (grade == "b"):
                  totalpoints = totalpoints + 3.0*3
                  count = 1
                  elif (grade == "C") or (grade == "c"):
                  totalpoints = totalpoints + 2.0*3
                  count = 1
                  elif (grade == "D") or (grade == "d"):
                  totalpoints = totalpoints + 1.0*3
                  count = 1
                  elif (grade == "F") or (grade == "f"):
                  totalpoints = totalpoints + 0.0*3
                  count =1
                  else:
                  print "The input you have entered is not valid"
                  count = 0
                  count=0
                  while count==0:

                  grade=raw_input ("please enter "+name+ "'s Chemistry grade: ")

                  if (grade == "A") or (grade == "a"):
                  totalpoints = totalpoints + 4.0*2
                  count = 1
                  elif (grade == "B") or (grade == "b"):
                  totalpoints = totalpoints + 3.0*2
                  count = 1
                  elif (grade == "C") or (grade == "c"):
                  totalpoints = totalpoints + 2.0*2
                  count = 1
                  elif (grade == "D") or (grade == "d"):
                  totalpoints = totalpoints + 1.0*2
                  count = 1
                  elif (grade == "F") or (grade == "f"):
                  totalpoints = totalpoints + 0.0*2
                  count =1
                  else:
                  print "The input you have entered is not valid"
                  count = 0
                  count=0
                  while count==0:

                  grade=raw_input ("please enter "+name+ "'s Physics grade: ")

                  if (grade == "A") or (grade == "a"):
                  totalpoints = totalpoints + 4.0*2
                  count = 1
                  elif (grade == "B") or (grade == "b"):
                  totalpoints = totalpoints + 3.0*2
                  count = 1
                  elif (grade == "C") or (grade == "c"):
                  totalpoints = totalpoints + 2.0*2
                  count = 1
                  elif (grade == "D") or (grade == "d"):
                  totalpoints = totalpoints + 1.0*2
                  count = 1
                  elif (grade == "F") or (grade == "f"):
                  totalpoints = totalpoints + 0.0*2
                  count =1
                  else:
                  print "The input you have entered is not valid"
                  count = 0

                  totalpoints = totalpoints/10
                  print "The gpa for "+name+" is",totalpoin ts


                  ask=raw_input(" would you like to calculate another GPA?: y/n:" )

                  if (ask == "y") or (ask == "Y"):
                  student=0
                  else:
                  student=1

                  raw_input("\n\n Thank you for using Mike's GPA calculator. Please press Enter to Exit.")
                  I don't think you need all that code:
                  [code=python]
                  courses ["Physics", "Chemistry" , "Math", "English"]
                  student=0
                  while student==0:

                  print "welcome to Mike's GPA calculator!"
                  name=raw_input( "please enter the name of the student: ")
                  totalpoints=0.0
                  for course in courses:
                  count=0
                  while count==0:
                  grade=raw_input ("please enter %s's %s grade: " % (name, course))

                  if grade.lower() == "a":
                  totalpoints = totalpoints + 4.0*2
                  count = 1
                  elif grade.lower() == "b"):
                  totalpoints = totalpoints + 3.0*2
                  count = 1
                  elif grade.lower() == "c"):
                  totalpoints = totalpoints + 2.0*2
                  count = 1
                  elif grade.lower() == "d"):
                  totalpoints = totalpoints + 1.0*2
                  count = 1
                  elif grade.lower() == "f"):
                  totalpoints = totalpoints + 0.0*2
                  count = 1
                  else:
                  print "The input you have entered is not valid"
                  #count = 0 no need to set it; if it goes to else; count is not 1

                  totalpoints = totalpoints/10
                  print "The gpa for "+name+" is",totalpoin ts


                  ask=raw_input(" would you like to calculate another GPA?: y/n:" )

                  if (ask == "y") or (ask == "Y"):
                  student=0
                  else:
                  student=1
                  [/code]
                  That should work.

                  Comment

                  • bartonc
                    Recognized Expert Expert
                    • Sep 2006
                    • 6478

                    #10
                    Originally posted by mdmytryk
                    I finished writing the program i was working on and was wondering if i could get some feedback on it. This was an assignment for a class, so some of the values were set by the professor, such as the number of classes, the lame greetings, etc. As far as i know, the program works, although im not sure how orthodox my coding is.
                    Orthodox?.. Well, not quite. You are close, but the loop inside a loop (as suggested by others) is more like what you want to shoot for.

                    HERE'S the BIGGIE: You must use CODE tags! Instructions are on the right hand side of the page while you are posting or replying.

                    Thanks.

                    Comment

                    • mdmytryk
                      New Member
                      • Sep 2007
                      • 12

                      #11
                      Thanks for the help guys, i have defiantly learned a thing or two. Last question, im sure my simpleton questions are getting a little tedious. I see that i should use a loop within a loop, makes sense. However, some of the classes in this program are 2 credit hour, and some are 3.

                      # this is the 2 credit hour class, notice how its multiplied by 2
                      totalpoints = totalpoints + 3.0*2

                      # this is the 3 credit hour class.
                      totalpoints = totalpoints + 3.0*3

                      Two of the classes are 2 credit hour, and the other two are 3. Would it be easier to use 2 separate loops, or would it make more sense to not have the values hard coded?

                      Thanks

                      Comment

                      • ilikepython
                        Recognized Expert Contributor
                        • Feb 2007
                        • 844

                        #12
                        Originally posted by mdmytryk
                        Thanks for the help guys, i have defiantly learned a thing or two. Last question, im sure my simpleton questions are getting a little tedious. I see that i should use a loop within a loop, makes sense. However, some of the classes in this program are 2 credit hour, and some are 3.

                        # this is the 2 credit hour class, notice how its multiplied by 2
                        totalpoints = totalpoints + 3.0*2

                        # this is the 3 credit hour class.
                        totalpoints = totalpoints + 3.0*3

                        Two of the classes are 2 credit hour, and the other two are 3. Would it be easier to use 2 separate loops, or would it make more sense to not have the values hard coded?

                        Thanks
                        It is still possible to use a single loop. You could have the credit hour as part of the list you use for the loop:
                        [code=python]
                        courses = [("Math", 2), ("Science", 3), ("English", 3), ("Chemistry" , 2)]

                        for (course, credit) in courses:
                        ... then ...
                        totalpoints += 3.0 * credit
                        [/code]
                        You could also rewrite the program without all those if statements to determine the grade:
                        [code=python]
                        import string
                        grades = [4.0, 3.0, 2.0, 1.0]

                        for (course, credit) in courses:
                        grade = raw_input("Ente r grade: ")
                        totalpoints += grades[string.lowercas e.index(grade.l ower())] * credit
                        [/code]
                        See if that works for you.

                        Comment

                        • bartonc
                          Recognized Expert Expert
                          • Sep 2006
                          • 6478

                          #13
                          Originally posted by mdmytryk
                          Thanks for the help guys, i have defiantly learned a thing or two. Last question, im sure my simpleton questions are getting a little tedious. I see that i should use a loop within a loop, makes sense. However, some of the classes in this program are 2 credit hour, and some are 3.

                          # this is the 2 credit hour class, notice how its multiplied by 2
                          totalpoints = totalpoints + 3.0*2

                          # this is the 3 credit hour class.
                          totalpoints = totalpoints + 3.0*3

                          Two of the classes are 2 credit hour, and the other two are 3. Would it be easier to use 2 separate loops, or would it make more sense to not have the values hard coded?

                          Thanks
                          Now you will truly see (and you questions are by no means tedious) the flexibility of list:[CODE=python]
                          print "welcome to the GPA calculator"


                          # start with a list of classes #
                          ClassNames = ('Physics', 'Chemistry', 'Math', 'English')
                          # assign each class a credit hour value #
                          CredHoursDict = dict(zip(ClassN ames, (2, 2, 3, 3,)))
                          print CredHoursDict
                          ##nClasses = len(ClassNames)
                          Grades = tuple("ABCDF")

                          # get the student's name
                          name = raw_input("plea se enter the name of the student ")

                          totalpoints=0.0
                          totalCreditHour s = 0

                          # Now, loop on the 'Classes' list - actaully a tuple of names
                          for className in ClassNames:
                          grade = None
                          while grade not in Grades:
                          # we'll use string formatting instead of addition
                          # variables are plugged into the '%s' locations #
                          grade = raw_input("plea se enter %s's %s grade " %(name, className))
                          grade = grade.upper()

                          credHours = CredHoursDict[className]
                          totalCreditHour s += credHours

                          if grade == "A":
                          totalpoints = totalpoints + (4.0 * credHours)

                          elif grade == "B":
                          totalpoints = totalpoints + (3.0 * credHours)

                          elif grade == "C":
                          totalpoints = totalpoints + (2.0 * credHours)

                          elif grade == "D":
                          totalpoints = totalpoints + (1.0 * credHours)

                          ## no need to add zero
                          ## elif grade == "F":
                          ## totalpoints = totalpoints + 0.0

                          print "The GPA is %.1f" %(totalpoints/totalCreditHour s)[/CODE]

                          Comment

                          • bartonc
                            Recognized Expert Expert
                            • Sep 2006
                            • 6478

                            #14
                            Originally posted by ilikepython
                            It is still possible to use a single loop. You could have the credit hour as part of the list you use for the loop:
                            [code=python]
                            courses = [("Math", 2), ("Science", 3), ("English", 3), ("Chemistry" , 2)]

                            for (course, credit) in courses:
                            ... then ...
                            totalpoints += 3.0 * credit
                            [/code]
                            You could also rewrite the program without all those if statements to determine the grade:
                            [code=python]
                            import string
                            grades = [4.0, 3.0, 2.0, 1.0]

                            for (course, credit) in courses:
                            grade = raw_input("Ente r grade: ")
                            totalpoints += grades[string.lowercas e.index(grade.l ower())] * credit
                            [/code]
                            See if that works for you.
                            I also like the tuple (humble beginnings of a true object) to define a "course".
                            I do not, however, find any redeeming qualities in this usage:
                            Code:
                            grades[string.lowercase.index(grade.lower())]
                            Sorry, my friend:
                            • too many functions squished into one line (there is no advantage in doing so)

                            Comment

                            • bartonc
                              Recognized Expert Expert
                              • Sep 2006
                              • 6478

                              #15
                              Originally posted by bartonc
                              I also like the tuple (humble beginnings of a true object) to define a "course".
                              In fact, I like it so much that I did a little rewrite:[CODE=python]
                              print "welcome to the GPA calculator"


                              # start with a list of classes #
                              ClassNames = ('Physics', 'Chemistry', 'Math', 'English')
                              # assign each class a credit hour value #
                              CourseTupleList = zip(ClassNames, (2, 2, 3, 3,))
                              print CourseTupleList
                              ##nClasses = len(ClassNames)
                              Grades = tuple("ABCDF")

                              # get the student's name
                              name = raw_input("plea se enter the name of the student ")

                              totalpoints=0.0
                              totalCreditHour s = 0

                              # Now, loop on the 'Courses' list - actaully a list of two-tuple of names, credit hours
                              for className, credHours in CourseTupleList :
                              grade = None
                              while grade not in Grades:
                              # we'll use string formatting instead of addition
                              # variables are plugged into the '%s' locations #
                              grade = raw_input("plea se enter %s's %s grade " %(name, className))
                              grade = grade.upper()

                              totalCreditHour s += credHours

                              if grade == "A":
                              totalpoints = totalpoints + (4.0 * credHours)

                              elif grade == "B":
                              totalpoints = totalpoints + (3.0 * credHours)

                              elif grade == "C":
                              totalpoints = totalpoints + (2.0 * credHours)

                              elif grade == "D":
                              totalpoints = totalpoints + (1.0 * credHours)

                              ## no need to add zero
                              ## elif grade == "F":
                              ## totalpoints = totalpoints + 0.0

                              print "The GPA is %.1f" %(totalpoints/totalCreditHour s)[/CODE]
                              welcome to the GPA calculator
                              [('Physics', 2), ('Chemistry', 2), ('Math', 3), ('English', 3)]
                              please enter the name of the student Barton
                              please enter Barton's Physics grade a
                              please enter Barton's Chemistry grade b
                              please enter Barton's Math grade c
                              please enter Barton's English grade b
                              The GPA is 2.9

                              Comment

                              Working...