- 2
Please can someone help with the code to BOOK TITLES and PHONE NUMBER VALIDATOR in python.
21 Antworten
+ 6
https://code.sololearn.com/c5LfMwEmIx2v/?ref=app
for book titles you can refer to the code above and if you have any problems just ask me
Phone validator:
first you need to define a function to count the no. of characters in the input and then apply if condition.
txt=input()
def count(text):
count=0
for c in text:
count+=1
return count
if txt.startswith("1") and count(txt)==8:
print("valid")
elif txt.startswith("8") and count(txt)==8:
print("valid")
elif txt.startswith("9") and count(txt)==8:
print("valid")
else:
print("invalid")
+ 20
import re
s=str(input())
c=r"(1|8|9)......."
match = re.search(c, s)
if (match and len(s)==8):
print("Valid")
else:
print("Invalid")
Follow me for more best solutions and more.
+ 8
You must using symbol $ :
"[189]\d{7}quot;
+ 5
import re
#your code goes here
num = input()
pattern = r"(1|8|9)\d{7}quot;
match = re.match(pattern,num)
if match:
print("Valid")
else :
print("Invalid")
+ 3
A simpler way with 5 lines of code.
A simple explanation, loop through all lines, and if a line has trailing/ending "\n" remove it from the count of the length.
https://code.sololearn.com/cdaPdMWWeN3W/?ref=app
+ 1
import re
monge=str(input())
gaspar=r"(1|8|9)......."
match = re.search(gaspar, monge)
if (match and len(monge)==8):
print("Valid")
else:
print("Invalid")
0
Give examples what is needed, and what is done already
0
For the BOOK TITLE
You have been asked to make a special book categorization program, which assigns each book a special code based on its title.
The code is equal to the first letter of the book, followed by the number of characters in the title.
For example, for the book "Harry Potter", the code would be: H12, as it contains 12 characters (including the space).
You are provided a books.txt file, which includes the book titles, each one written on a separate line.
Read the title one by one and output the code for each book on a separate line.
For example, if the books.txt file contains:
Some book
Another book
Your program should output:
S9
A12
0
Thanks....
0
https://www.w3schools.com/JUMP_LINK__&&__python__&&__JUMP_LINK/python_regex.asp
actually I’m still a beginner and i haven’t studied regex module yet but you can try this link (-.-;)y-~
0
Hi,
I cannot to figure out why fails on test my code...
Any idea?
```
import re
#your code goes here
n = input()
result = re.match("[189]\d{7}", n)
if result:
print("Valid")
else:
print("Invalid")
```
0
Can anyone help in solving phone number validator program in python
0
import re
#your code goes here
n=input()
pattern=r"^1|8|9\r[1-9]quot;
match= re.search(pattern,n)
if(match and len(n)==8):
print ("Valid")
else:
print("Invalid")
- 1
About that Phone number validator...
What if i want to do it with REGEX....
Because, that was the hint they give...
- 1
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.
import re
monge=str(input())
gaspar=r"(1|8|9)......."
match = re.search(gaspar, monge)
if (match and len(monge)==8):
print("Valid")
else:
print("Invalid")
- 1
import re
monge=str(input())
gaspar=r"(1|8|9)......."
match = re.search(gaspar, monge)
if (match and len(monge)==8):
print("Valid")
else:
print("Invalid")
- 1
# BOOK TITLES
# -------------------
file = open("/usercode/files/books.txt", "r")
lines = file.readlines()
for l in lines:
print(f'{l[0]}{len(l.strip())}')
file.close()
# --------------------------------------------------------
# PHONE NUMBER VALIDATOR
# ^ --> starts with, $ --> ends with
# ---------------------------------------
import re
if re.search('^(1|8|9)\d{7}#x27;, input()):
print("Valid")
else:
print("Invalid")
- 1
import re
#your code goes here
number = input()
pattern = r"[1|8|9]+.......quot;
if re.match(pattern,number):
print("Valid")
else:
print("Invalid")
- 1
# 8 digit Phone number generator
import re
num = input()
pattern = r"[1|8|9]\d{7}quot;
if re.match(pattern , num):
print ("Valid ")
else:
print ("Invalid")
Good luck to everyone 🙏
- 4
And for the 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