- 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 :)

26th Jan 2022, 7:18 PM
Jessica
10 RĂ©ponses
+ 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")
27th Jan 2022, 4:30 PM
Muhammad Galhoum
Muhammad Galhoum - avatar
+ 1
Muhammad okay thank you
27th Jan 2022, 4:36 PM
Jessica
+ 1
You're welcome Jessica
27th Jan 2022, 4:48 PM
Muhammad Galhoum
Muhammad Galhoum - avatar
0
What exactly is your code supposed to do? And why did you import re but never use it?
26th Jan 2022, 7:50 PM
Lisa
Lisa - avatar
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")
26th Jan 2022, 8:03 PM
Sousou
Sousou - avatar
0
Import re was already there but I don’t really know what it means!
27th Jan 2022, 4:17 PM
Jessica
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
27th Jan 2022, 4:23 PM
Jessica
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
28th Jan 2022, 2:40 AM
Saad Khan
Saad Khan - avatar
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, 👍"""
28th Jan 2022, 6:19 PM
Shantanu Bindhani
Shantanu Bindhani - avatar
- 1
Second to last project in python thanks for helping me
27th Jan 2022, 4:16 PM
Jessica