+ 2

how to validation apply on String

There is the My Code : my Requirement is If Any One Can Enter "String" Skipping the Number. than it Will Be Show This Message. " You Must Should Enter a Number Not any String" if some one Enter the String like 'any name', 's' or etc. print("squre root of n Number") n1=input("Enter the N'th Number :\n") i=1 n=int(n1) if True: while i<=n: power=pow(i,2) print(i,"=",power) i+=1 else: print("You Must Should Enter a Number Not any String") print("End")

8th Feb 2018, 8:00 PM
suneel singh
suneel singh - avatar
2 Respuestas
+ 3
use regex import re and put condition as, if re.match("\d+", i): Here, i is the number in string format. If i is integer, it will execute if block. If i is string, it will execute else block.
8th Feb 2018, 11:14 PM
Rex Terminous
Rex Terminous - avatar
+ 2
nice good , regular expression . I just not about the regex recently I am start . okk thank you I try it
9th Feb 2018, 4:54 AM
suneel singh
suneel singh - avatar