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


Re: [Tutor] Python Questions

2017-07-18 Thread Mats Wichmann
On 07/18/2017 11:42 AM, Alan Gauld via Tutor wrote:
> On 18/07/17 11:41, Max Smith wrote:
> 
>> What's the easiest way to learn python currently 
> 
> Write a lot of code.
> 
> As to which tutorial to follow, that's a very personal choice and
> depends on your previous knowledge and learning style. If you can
> already program in a similar language(say Perl, PHP or Javascript)
> then the official tutorial is just fine. If you are a comp-lete
> programming neophite then use one of the non programmers
> tutorials on the python web site (eg mine :-)
> 
> You can start with some of the many YouTube video courses if you
> prefer but none of these will give you the depth that a
> written tutorial will.

Absolutely, write code.  Some of the tutorials try hard to give you
"real" problems to solve, but they're by their nature prepared to
illustrate some point. It really helps if you supplement by using Python
to try to solve some distinct problem that interests you, because
ultimately what counts is whether you can apply your new knowledge to a
brand new situation, not one that's been hand-crafted by an author. If
you're doing that and get stuck, this is a place that can help with the
unsticking...

I'll just end up parroting Alan so I'll defer mentioning how hard it is
to choose "the best" "the easiest" "the fastest".  Do look at his
material by all means.

Google certainly knows what they're doing with Python, nothing wrong
with pursuing their stuff.

A python learning site that happens to appeal to me (one person's
opinions, and all that) is: http://www.python-course.eu/

AND there's actually one site that claims it is addressing the Computing
GCSE, http://usingpython.com/ - this one I have never looked at but it
might be worth a glance since that's the direction you're coming from.



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


Re: [Tutor] Python Questions

2017-07-18 Thread Alan Gauld via Tutor
On 18/07/17 11:41, Max Smith wrote:

> What's the easiest way to learn python currently 

Write a lot of code.

As to which tutorial to follow, that's a very personal choice and
depends on your previous knowledge and learning style. If you can
already program in a similar language(say Perl, PHP or Javascript)
then the official tutorial is just fine. If you are a comp-lete
programming neophite then use one of the non programmers
tutorials on the python web site (eg mine :-)

You can start with some of the many YouTube video courses if you
prefer but none of these will give you the depth that a
written tutorial will.

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


[Tutor] Python Questions

2017-07-18 Thread Max Smith
I have some questions about python.



What's the easiest way to learn python currently I'm using google's excersise 
program, I'm just reading and making notes then testing out what I have learnt. 
Since I' need to understand python fully as I've got a exam in Python for my 
GCSE's if you could give me some tips. I'd be excited to hear.



Thanks very Much,

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