+ 5

Where is the problem? Variable Name Validation

https://code.sololearn.com/cW3mnzHOWzN8/?ref=app Input: £45 Output: Valid

8th Feb 2019, 2:50 AM
Ayush Sinha
Ayush Sinha - avatar
7 Réponses
+ 10
Either Python or Sololearn can't handle the £ symbol. If you add this line: print([k for k in otherInvalid]) you'll see that £ is replaced by ú. You can add these lines to enable unicode support: import unicodedata import sys, codecs sys.stdout = codecs.getwriter('utf_16')(sys.stdout.buffer, 'strict') Unfortunately, now £ will be replaced by a different symbol in Sololearn when the input prompt is used and the code still won't work :-/
8th Feb 2019, 5:34 AM
Anna
Anna - avatar
+ 6
I think your code might run in other platforms. It's just that Sololearn seems to use a different encoding, so when you enter the pound sign, it is recognized as "ú". You can't really change that. It's not a problem with your code but with the way that Sololearn handels user input (I think).
8th Feb 2019, 12:42 PM
Anna
Anna - avatar
+ 6
Thanks for your help... 😄
8th Feb 2019, 12:53 PM
Ayush Sinha
Ayush Sinha - avatar
+ 5
Anna So, what should be the other logic?
8th Feb 2019, 12:32 PM
Ayush Sinha
Ayush Sinha - avatar
+ 5
Thank you Damiano Cangini, for your help..... 😄 from where I can learn these modules in python??
8th Feb 2019, 1:12 PM
Ayush Sinha
Ayush Sinha - avatar
+ 2
Also there is a nice method to check wheater a string is a valid identifier: str.isidentifier() Your validator function could be as easy as this from keyword import iskeyword def Validator(v): if v.isidentifier() and not iskeyword(v): return True return False
8th Feb 2019, 12:55 PM
Damiano
Damiano - avatar
+ 1
You can find methods for built-in types in the original documentation. https://docs.python.org/3/library/stdtypes.html#string-methods
8th Feb 2019, 1:37 PM
Damiano
Damiano - avatar