[Tutor] Identify whether a character is unicode control.

Alan Gauld alan.gauld at yahoo.co.uk
Wed Sep 16 20:22:57 EDT 2020


On 16/09/2020 23:49, Alexandro Gon San wrote:
> My code:
> 
> import random
> def char_is_control(char):
>     #TODO
>     None

This looks suspiciously like homework which we will not do for you.

However I would say that None on its own does not do anything useful.

So ask yourself some questions, and tell us the answers if you still
need help...

1) What should the function return - what type of result?
2) How do you define a unicode control character? What exactly,
   and I do mean *exactly* are you looking for?


> string = ''
> while len(string)<100000:
>     number = random.randint(0,(256**4)-1)
>     char = (number).to_bytes(4,byteorder='big').decode("utf_8",'ignore')
>     if not char_is_control(char):
>         string += char
> 

I would suggest you probably want some kind of output
or your program will be very boring.
Maybe print the string?

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