+ 5
Where is the problem? Variable Name Validation
https://code.sololearn.com/cW3mnzHOWzN8/?ref=app Input: £45 Output: Valid
7 ответов
+ 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 :-/
+ 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).
+ 6
Thanks for your help... 😄
+ 5
Anna So, what should be the other logic?
+ 5
Thank you Damiano Cangini, for your help..... 😄
from where I can learn these modules in python??
+ 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
+ 1
You can find methods for built-in types in the original documentation.
https://docs.python.org/3/library/stdtypes.html#string-methods