Noob coding question

Here was the exercise i had to do, however I tried some modifications but i failed in it. I wanted to do so that you can put yourself the mark you got, and after it, it will return your letter note value. Probably is a noob mistake, but i have tried a lot of things and still dont work. Could someone tell me where did I confuse, and how would be the right way to do it?:sweat_smile::smile:

grade = raw_input (“Whats your mark?”)

def grade_converter(grade):
if grade >= 90:
return “A”
elif grade < 90 and grade >= 80:
return “B”
elif grade < 80 and grade >= 70:
return “C”
elif grade < 70 and grade >= 65:
return “D”
elif grade < 65 and grade >= 0:
return “F”
return “Isnt a valid note”

print "you have gotten a " + grade_converter(grade)

Hey @beta9821014389! Will you please format your code like this topic tells you?

That will allow us to see if you had any whitespace mistakes

1 Like

it say I have no access to the topic :thinking::thinking:

Yeah, there is a problem with the link in @stevencopeland’s post. Assuming you have indented properly, your main issue is that the value assigned to your grade variable is a string. You can’t compare a string to an integer in your grade_converter function. Converting grade to an integer with the int() method will fix that. Your function will work, but it isn’t necessary to check the between-ness of the grade. You could simply check if the grade is greater than the uppermost value for each subsequent grade like so:

if grade > 89:
  return "A" #the return statement will exit the function, so no need for a less than comparison
elif grade > 79:
  return "B"
#and etc.

Hope this helps!

I’ve included your code with my suggestions here if you’d like to take a peek:

grade = int(raw_input("What's your mark? "))

def grade_converter(grade):
  if grade > 89:
    return "A"
  elif grade > 79:
    return "B"
  elif grade > 69:
    return "C"
  elif grade > 59:
    return "D"
  elif grade >= 0:
    return "F"
    return "Isn't a valid note"

print"You have gotten a " + grade_converter(grade)

This is the same post @stevencopeland shared a link to. This link seems to work.


Weird… sorry about that, I can get on the post so I didn’t you weren’t able too.

1 Like

Yeah, it’s weird. I’m not sure why it doesn’t work. This is what comes up: