[Tutor] Question on If/Elif Statement in Python

Alan Gauld alan.gauld at yahoo.co.uk
Wed Aug 12 18:38:20 EDT 2020


On 12/08/2020 17:39, eric grunfeld wrote:

> I wanted to get your thoughts if I am running this correctly (I always seem
> to have issues with indentation, since I am new to programming Python)

Terminology is very important in programming.
You ask if you are "running" it correctly.
That means you asking us if you are executing
the program correctly. But you don't tell us
how you run it.

I'm going to assume for now you want to know
if you are writing the code correctly.
ie if the layout is  sensible.

The answer is yes, it all looks fine.
You should have gotten the correct answers
when you did run it.

> def number_group(number):
>   if number > 0:
>     return "Positive"
>   elif number < 0:
>     return "Negative"
>   else:
>     return "Zero"
> 
> print(number_group(10)) #Should be Positive
> print(number_group(0)) #Should be Zero
> print(number_group(-5)) #Should be Negative

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list