0
Solve using basic conditions of python
Phone Number Validator 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
9 odpowiedzi
+ 2
number = int(input())
if len(str(number))==8:
if (str(number)[0]=="1" or str(number)[0]=="8" or str(number)[0]=="9"):
print("Valid")
else:
print("Invalid")
else:
print("Invalid")
#I have tried this out and this works;)
+ 2
And Shahram's code is working buddy
+ 1
Use if else condition to check if length of the string is equal to 8 and check if string[0]==1 or 8 or 9
If all conditions return true print Valid else print Invalid.
+ 1
Please send the code
+ 1
phone = input()
if (len(phone)==8) and (phone[0]=="1" or phone[0]=="8" or phone[0]=="9"):
print('Valid')
else:
print('Invalid')
+ 1
num = input ("Enter number: ")
if len(num) > 8:
print("Invalid")
elif num[0] != 1 or num[0] != 8 or num[0] != 9:
print("Invalid")
else:
print("Valid")
😭😭😭 I know it's long but don't worry about me, I'll be fine
+ 1
Hey it's not working for 81234567
+ 1
Why the rest of code are not working except yours... What's the problem in there code ?
+ 1
In Stephen's code, you can see in the elif statement that he compared the not equal value with integers, whereas he has taken an input of string, "1","8","9"..it should be like this.