[Tutor] uplownumpnct.py

Alan Gauld alan.gauld at yahoo.co.uk
Fri Dec 29 20:37:15 EST 2023


On 29/12/2023 20:43, Ethan Rosenberg wrote:

> What is syntax error?

Please always post the full error message. Python error
messages are extremely informative (once you figure out
how to read them! And even more so in the most
recent versions)

> lgn = len(sent)
> lgn2 = lgn

You don't user either iof these variables  although I
guess you plan to later?) so they are irrelevant to
this example. Cutting out irrelevant code helps us
(and you?) locate the error more quickly.

> if letter in sent:
>     x=letter.isupper():
>         if x = 1:

There is no need to indent the if statement - and
in fact it is a syntax error to do so. (Although
it will reported as an Indentation error.)
Also you should be using == to test equality.
A single = is an assignment and not allowed in
an if expression. So two errors in a single line!.

Also since isupper() is a predicate you should
really test for truth not for a number so either:

if x == True:

or

if x:

or even better, combine the lines:

if letter.isupper():

Or even combine all three lines:

if letter in sent and letter.isupper():
   print('wow')

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