Lowest price ever! Learn Generative AI for 48% less!
Get my discount+ 12
My Code:
import re
#your code goes here
num = str(input())
pattern = "\A(1|8|9)\d{7}quot;
if re.match(pattern,num):
print("Valid")
else:
print("Invalid")
May It Helps You ☺️
+ 2
I am trying all these methods but they only work for a few of them and not for all.
But thanks everyone for helping, I really appreciate it.
0
This code will always print Invalid.
The Line: while phone==8:
will always evaluate false as phone will not be equal 8
You should use if statement with the len function and no need of continue statement.
And you can't check three values with startswith method so you check all values using or statement.
So Right Code:
phone = input()
if len(phone)==8:
if phone.startswith("1") or phone.startswith("8") or phone.startswith("9"):
print("Valid")
else:
print("Invalid")
else:
print("Invalid")
But You Should Use Regular Expression
May It helps You ☺️