[Tutor] uplownumpnct.py

Mats Wichmann mats at wichmann.us
Mon Jan 1 14:42:14 EST 2024


On 1/1/24 10:22, Ethan Rosenberg wrote:
> Tutor -
> 
> What is my syntax error?

As people have asked you *multiple* times before, paste the full error 
message.  It will tell you what the syntax error is. If you don't 
understand it, someone can help interpret - that's a whole lot easier 
than looking at code (often malformed by the mailer).

This is an obvious one:

 > pnct = [:,;.,,]
 > spec = [!,@,<,#,>,},$,%,&,?,*,(,),{,/,' ']

You can't just toss in a bunch of character that have syntactic meaning 
to Python. If you want a set of characters, you need to present them as 
a set of characters - since you're defining these as a list, you should 
enclose each punctuation/special character in quotes. If one of them is 
a quote itself, use the other quote mark for it.

Also, you can get these from Python

 >>> import string
 >>> string.punctuation
'!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'




More information about the Tutor mailing list