+ 2
I dont know how to code a question. Can somebody help me please
With ReGex utilities I want to write a code which gets some input lines and check whether these lines have real number or not if they have,print legal and if not,print illegal A real number can have decimal point and can be powered to a number which starts with e or E but the power just can be a real number the power can be negative or positive like 1.5e+2 If there is decimal point in the number, it has to be between two real number like 3.9 is legal but 3. is illegal. Between the number cant exist any space but before or after the number, it can have space Thanks a lot🙏
2 Réponses
+ 3
i hope this helps you
import re
while True:
pattern=r"((\d+((\s*[^\.\d\s])|(\.(\d+))))|(\d$))(e[+-]?\d+(\.\d+)?)?"
"""first part is for numbers without being powered to a number
and the rest are for powering part """
x=input("please enter your number:")
Find=re.search(pattern,x)
if Find:
print("legal")
if not Find:
print("illegal")
if x=="":
break
+ 3
Thanks a lot Sajad 🙏🙏