r/pythonhelp • • Aug 06 '21

HOMEWORK Having trouble categorising a number as a letter (check comments for context)

Post image
2 Upvotes

5 comments sorted by

3

u/MrPhungx Aug 06 '21

The first problem I see is that the If Statement is not indented correctly. It needs to be one indendation deeper than the def line of the function. Next you are not doing anything when the If Statement is true. You just wrote ('M'). If you would do my_var = ('M') you would effectively create a tuple containing a single String entry. What you probably want to do is Something like this:

if latitude > -8.0 and latitude < 0:
    return 'M'

1

u/bin_chicken Aug 06 '21

Thank you very much for explaining the concept behind it as well, you’re a life saver!

1

u/bin_chicken Aug 06 '21

I’ll preface by saying this is my first exposure to coding ever and am currently trying to come to grips with basic concepts. I think the aim of this code is to convert the float(-5.6) into the string of ‘M’. Sorry if this thread gets a lot of homework posts but this code is obviously not working and I don’t even know what to look up on YouTube tutorials.

1

u/bin_chicken Aug 06 '21

Also my code starts at the “if (latitude>(-8.0) and latitude<(0.0)):”

1

u/tejub6 Aug 06 '21

Missing indentation