Does this achieve the same thing?

You must select a tag to post in this category. Please find the tag relating to the section of the course you are on E.g. loops, learn-compatibility
So I was working through the control flow lessons for python 3
I did an activity and it said my code was right , out of curiosity I looked at the solution to see of they matched. And to my surprise there was a small difference. I wanted someone to double check I had it right and that maybe the way I did it was just another solution to the same problem
https://gist.github.com/0a0293ade8289244620a7e546bbb0ede (This is their solution)

https://gist.github.com/41aece0f60334e7238af752dc205ad6a (This is my solution)

In case the links don’t work properly -
Their solution:
def grade_converter(gpa):

grade = “F”

if gpa >= 4.0:

grade = "A"

elif gpa >= 3.0:

grade = "B"

elif gpa >= 2.0:

grade = "C"

elif gpa >= 1.0:

grade = "D"

return grade

My Solution:
def grade_converter(gpa):

if gpa >= 4.0:

return "A"

elif gpa >= 3.0:

return "B"

elif gpa >= 2.0:

return "C"

elif gpa >= 1.0:

return "D"

elif gpa >= 0.0:

return "F"

grade = gpa

(Sorry, I am new to this forum, please help haha)

Hello @cloud6257932118, welcome to the forums! If the numbers are not negative, then yes, the two solutions do the same thing. If you had a gpa of -1, then yours wouldn’t return anything. But for the purposes of the exercise, yes the solutions do the same thing.


To see how to correctly format code in the forums, see this post.

1 Like

Okay that is awesome! Thank you so very much!
I see what you mean now with the -1 problem. I live in a country which doesn’t use a GPA system so I don’t even know if that is possible hahaha. But yeah I see what you mean with the bug :slight_smile:

1 Like

I should hope no-one ever does get a GPA below 0; that’s worse than failing everything!

:rofl: :rofl: :rofl: :rofl: :rofl: hahaha I see!

1 Like