[Tutor] uplownumpnct.py

Alan Gauld alan.gauld at yahoo.co.uk
Mon Jan 1 14:43:58 EST 2024


On 01/01/2024 17:22, Ethan Rosenberg wrote:
> Tutor -
> 
> What is my syntax error?

I don't know, where does Python say it is?
Always post the full error message they tell us
so much useful information and saves us having
to guess!

> #uplownumpnct.py
> #To determine uppercase, lowercase, punctuation and special characters in a
> string
> 
> 
> up=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
> numm = [1,2,3,4,5,6,7,8,9,0]
> pnct = [:,;.,,]
> spec = [!,@,<,#,>,},$,%,&,?,*,(,),{,/,' ']
> 
> sent = 'THIS is the way we wash 1 2 3 , , !'
> list2 = list(sent)
> lgn = len(sent)
> lgn2 = lgn
> print(lgn)
> 
> for i in range(0,lgn-1):
> {
>         if list2[i] in up:
>             upp+=

I don't know what you expect this to do but, whatever
it is, it won't!

Same with these below...

> 
>        if list2[i] in  low:
>             lww+=
> 
>        if list2[i]  in numm:
>             numnum+=
> 
>        if list2[i] in pnct:
>             numpct+=
> 
>        if list2[i] in spec:
>             numspec+=
> 
> }
> 
>      prnt
> 
> def prnt:

This might be it? def defines a function.
A function has a parameter enclosed parameter list(possibly empty)


>      print('Num uppercase  ', upp)
>      print('Num lowercase  ',lww)
>      print('Num  numbers ',  numnum)
>      print('Num  punctuation  ', numpnct)
>      print('Num  special characters' , numspec)
>            #uplownumpnct.py

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