Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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 ☺️
22nd Oct 2020, 7:18 PM
Hacker Badshah
Hacker Badshah - avatar
+ 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.
1st May 2021, 12:06 PM
Halima Vohra
Halima Vohra - avatar
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 ☺️
22nd Oct 2020, 7:17 PM
Hacker Badshah
Hacker Badshah - avatar