Isnumeric() function don't works correctly. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Isnumeric() function don't works correctly.

I am working on a affine cipher, and I want to add the possibility to use negative numbers. I have in my program a condition for verify if the keys entered by the user are integers using the isnumeric() function. But, as you can see on my program, I had to remove the "-" sign using the replace() function to verify if the string is a number. But, when this test occur It tells me that it's not a number... What have I done wrong ? P. S. : I know that after correct this problem I have to make a backup for the initial keys to recover them after replace the string. https://code.sololearn.com/c4n2rDZPx8yX/?ref=app

17th Jul 2021, 1:42 PM
Skeelter
Skeelter - avatar
6 Answers
+ 3
def isValid(message): allowed="0123456789-" if all([i in allowed for i in message]): return True return False
17th Jul 2021, 2:54 PM
Oma Falk
Oma Falk - avatar
+ 1
in stead of answering, could i ask a question?😳😳😳😳
17th Jul 2021, 1:48 PM
Ehem
Ehem - avatar
+ 1
Thanks you :D
17th Jul 2021, 3:01 PM
Skeelter
Skeelter - avatar
0
Of course you can ! But bro if it's because my english is bad or I look like a script kiddie I apologize x)
17th Jul 2021, 1:50 PM
Skeelter
Skeelter - avatar
0
What does the following code do ? if replacedA.isnumeric() == False or replacedB.isnumeric() == False
17th Jul 2021, 1:58 PM
Abhay
Abhay - avatar
0
It supposed to stop the program if replacedA or replacedB are not numbers
17th Jul 2021, 2:00 PM
Skeelter
Skeelter - avatar