If elif for Grade Convertor

Hi Community,

I modified the final exercise in Conditionals with which asks you to write conditionals for grading.

I modified it to include the raw_input to seek the grade from the user and then print the result. The code is written as given in the image below. I get the error “Traceback”.

Could someone explain where I am bungling.

Help will be appreciated!

Thanks.

I’ve not checked that code in detail but it’s probably fine. If you can try it on your own system, you’d know for certain.

I belive there are quite a few lessons where raw_input and similar commands are disabled/broken in some way so that they can’t be used. You’ll need to complete the lesson without them.

Hi, welcome to the forums! If you are planning to further consult the forums, make sure to post your code formatted for easy access! You can go to this link for more information.


Also, don’t forget to post a link to the exercise!

Noted will make the changes!

Thanks!

1 Like

Okay!

I will consider your advice and try it out in the system rather than CodeAcademy.

If you do get time please go through once again and let me know my mistakes.

Thanks for your time.

This is my code which I wrote.

def score(grade):
  if (grade >= 90):
    print "Excellent"
  elif (grade <= 89 and grade >= 80):
    print "Very Good "
  elif (grade <= 79 and grade >= 70):
    print "Good"     
  elif (grade <= 69 and grade >= 65):
    print "Satisfactory"
  elif (grade < 65 and grade >= 60):
    print "Can do Better"
  else :
    print "Improvement Needed!"

  grade = int(raw_input("Enter your Grade"))

  print score(grade)   

First of all, why don’t you have parenthesis around your print statements?
Secondly like @tgrtim said, raw_input and similar commands may be disabled for some lessons, so you should just try doing it the normal way (to pass the module first):

grade = 'number'
score(grade)

And after taking a look at your code here is the fixed version:

def score(grade):
  if (grade >= 90):
    print("Excellent")
  elif (grade <= 89 and grade >= 80):
    print("Very Good ")
  elif (grade <= 79 and grade >= 70):
    print("Good")     
  elif (grade <= 69 and grade >= 65):
    print("Satisfactory")
  elif (grade < 65 and grade >= 60):
    print("Can do Better")
  else :
    print("Improvement Needed!")

grade = int(raw_input("Enter your Grade"))

score(grade)

This code would probably not work in Codecademy (because of the input), however it works fine elsewhere if you really want to use input.

1 Like

Thanks @h1lo.

I will try it outside of the CodeAcademy environment. I did do it the normal way and passed the module. Just wanted to challenge myself.

Also what about the parenthesis in the print command?
Is it just good code housekeeping habit or has some functional aspect too?

1 Like

Well, this code would have been fine if it was python 2, but since in python 3, the print statement was made a function, parenthesis are required.

1 Like

Challenging yourself is good! I wish you luck on your coding journey! :smile:

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.