- 1
Phone number validating
I want to know why this code wonât work please import re x = (input()) if x[0] == 1: print("Valid") if x[0] == 8: print("Valid") if x[0] == 9: print("Valid") else: print("Invalid") Thank you :)
10 Answers
+ 2
This is the code for your question
Jessica
x = input()
if (x[0] == "1" or x[0] == "8" or x[0] == "9") and len(x) == 8:
print("Valid")
else:
print("Invalid")
+ 1
Muhammad okay thank you
+ 1
You're welcome Jessica
0
What exactly is your code supposed to do? And why did you import re but never use it?
0
#to make it work properly (idk the task)
x = input()
if x[0] == "1":
print("Valid")
elif x[0] == "8":
print("Valid")
elif x[0] == "9":
print("Valid")
else:
print("Invalid")
0
Import re was already there but I donât really know what it means!
0
You are given a number input, and need to check if it is a valid phone number.
A valid phone number has exactly 8 digits and starts with 1, 8 or 9.
Output "Valid" if the number is valid and "Invalid", if it is not.
Sample Input
81239870
Sample Output
Valid
0
re is imported without any reason.
also you are taking input as string.
just use
x = int(input())
then all values will be compared
0
That re(regular expression/regex) problem
Solution :
import re
def check(phno):
Pattern = re.compile("(0|91)?[7-9][0-9]{10}")
return Pattern.match(phno)
check(input())
"""and i would recommend you learn regex, instead of hard-coding, đ"""
- 1
Second to last project in python thanks for helping me