Re: [Tutor] if/else statement

2017-07-18 Thread Mats Wichmann
And one more, the 'if' needs a colon at the end

On July 18, 2017 5:10:30 PM MDT, Alan Gauld via Tutor  wrote:
>On 18/07/17 18:31, Shane Johnson (shanejoh) wrote:
>
>> def greater_less_equal_5(answer):
>>if answer is '>' 5
>>return 1
>>elif answer is < 5:
>>return 0
>>else:
>>return 4
>
>> I’m getting a invalid syntax line 2 error. Any assistance is greatly
>appreciated.
>
>Thee are two problems.
>
>1) 'is' is a problem, you don't need it here. 'is' is an operator
>for testing whether two object references are to the same
>actual object
>eg.
>
>x = 42
>y = x   # y and x both refer to the same number
>if x is y: print 'yes!'
>
>You don't use it in mathematical comparisons so your code
>should look like:
>
>   if answer > 5
>  return 1
>   elif answer < 5:
>  return 0
>   else:
>  return 4
>
>Notice I also removed the quotes around the > sign and
>added indentation to the return statements which leads
>us to...
>
>2) You don't have any indentation in the function body.
>Indentation is all important in Python, it's how the
>interpreter knows where the conditional block starts
>and stops.
>
>HTH
>-- 
>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
>
>
>___
>Tutor maillist  -  Tutor@python.org
>To unsubscribe or change subscription options:
>https://mail.python.org/mailman/listinfo/tutor

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] if/else statement

2017-07-18 Thread Alan Gauld via Tutor
On 18/07/17 18:31, Shane Johnson (shanejoh) wrote:

> def greater_less_equal_5(answer):
>if answer is '>' 5
>return 1
>elif answer is < 5:
>return 0
>else:
>return 4

> I’m getting a invalid syntax line 2 error. Any assistance is greatly 
> appreciated.

Thee are two problems.

1) 'is' is a problem, you don't need it here. 'is' is an operator
for testing whether two object references are to the same
actual object
eg.

x = 42
y = x   # y and x both refer to the same number
if x is y: print 'yes!'

You don't use it in mathematical comparisons so your code
should look like:

   if answer > 5
  return 1
   elif answer < 5:
  return 0
   else:
  return 4

Notice I also removed the quotes around the > sign and
added indentation to the return statements which leads
us to...

2) You don't have any indentation in the function body.
Indentation is all important in Python, it's how the
interpreter knows where the conditional block starts
and stops.

HTH
-- 
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


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] if/else statement

2017-07-18 Thread Joel Goldstick
On Tue, Jul 18, 2017 at 1:31 PM, Shane Johnson (shanejoh) <
shane...@cisco.com> wrote:

> I am doing the codeacademy python class and have the following code:
>
> def greater_less_equal_5(answer):
>if answer is '>' 5
>
indent the line after the if

>return 1
>elif answer is < 5:
>
and here

>return 0
>else:
>
and here

>return 4
>
> print greater_less_equal_5(4)
> print greater_less_equal_5(5)
> print greater_less_equal_5(6)
>
> I’m getting a invalid syntax line 2 error. Any assistance is greatly
> appreciated.
>
> [cid:image001.png@01D2FFCA.286FD4E0]
> Shane Johnson
> Network Consulting Engineer
> Cisco Services
> shane...@cisco.com
> Phone: +1 770-236-3970
> Mobile: +1 404-966-5334
>
> In python, indentation is essential
> Cisco.com
>
>
>
> [cid:image002.png@01D2FFCA.286FD4E0]Think before you print.
>
> This email may contain confidential and privileged material for the sole
> use of the intended recipient. Any review, use, distribution or disclosure
> by others is strictly prohibited. If you are not the intended recipient (or
> authorized to receive for the recipient), please contact the sender by
> reply email and delete all copies of this message.
> For corporate legal information go to:
> http://www.cisco.com/web/about/doing_business/legal/cri/index.html
>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] if/else statement

2017-07-18 Thread Shane Johnson (shanejoh)
I am doing the codeacademy python class and have the following code:

def greater_less_equal_5(answer):
   if answer is '>' 5
   return 1
   elif answer is < 5:
   return 0
   else:
   return 4

print greater_less_equal_5(4)
print greater_less_equal_5(5)
print greater_less_equal_5(6)

I’m getting a invalid syntax line 2 error. Any assistance is greatly 
appreciated.

[cid:image001.png@01D2FFCA.286FD4E0]
Shane Johnson
Network Consulting Engineer
Cisco Services
shane...@cisco.com
Phone: +1 770-236-3970
Mobile: +1 404-966-5334


Cisco.com



[cid:image002.png@01D2FFCA.286FD4E0]Think before you print.

This email may contain confidential and privileged material for the sole use of 
the intended recipient. Any review, use, distribution or disclosure by others 
is strictly prohibited. If you are not the intended recipient (or authorized to 
receive for the recipient), please contact the sender by reply email and delete 
all copies of this message.
For corporate legal information go to:
http://www.cisco.com/web/about/doing_business/legal/cri/index.html



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor