- 2

Please can someone help with the code to BOOK TITLES and PHONE NUMBER VALIDATOR in python.

12th Oct 2020, 11:59 AM
Agboola Vincent
Agboola Vincent - avatar
21 Respostas
+ 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")
13th Oct 2020, 8:38 AM
Ren
+ 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.
25th Oct 2020, 4:19 PM
Karan
Karan - avatar
+ 8
You must using symbolĀ $Ā : "[189]\d{7}
quot;
21st Oct 2020, 6:35 PM
Zara Taghizadeh
+ 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")
27th Feb 2021, 7:31 PM
BrijNandan Tripathi
BrijNandan Tripathi - avatar
+ 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
15th Dec 2020, 6:41 PM
Lam Wei Li
Lam Wei Li - avatar
+ 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")
4th Jan 2021, 3:28 PM
Oumar TOURE
Oumar TOURE - avatar
0
Give examples what is needed, and what is done already
12th Oct 2020, 12:02 PM
Alex Vernee
Alex Vernee - avatar
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
12th Oct 2020, 12:04 PM
Agboola Vincent
Agboola Vincent - avatar
0
Thanks....
13th Oct 2020, 12:16 PM
Agboola Vincent
Agboola Vincent - avatar
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-~
13th Oct 2020, 3:05 PM
Ren
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") ```
16th Oct 2020, 8:10 PM
Csaba Cselko
Csaba Cselko - avatar
0
Can anyone help in solving phone number validator program in python
22nd Oct 2020, 4:30 AM
Eedula Ganeshreddy
Eedula Ganeshreddy - avatar
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")
5th Feb 2022, 11:34 AM
Ruchi Shah
- 1
About that Phone number validator... What if i want to do it with REGEX.... Because, that was the hint they give...
13th Oct 2020, 12:18 PM
Agboola Vincent
Agboola Vincent - avatar
- 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")
21st Jan 2021, 6:52 PM
Syed Fahad Ahmed
Syed Fahad Ahmed - avatar
- 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")
8th May 2021, 5:53 PM
Ajinkya khandagale
Ajinkya khandagale - avatar
- 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")
7th Jun 2022, 2:27 PM
Mahmoud Nagy
Mahmoud Nagy - avatar
- 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")
30th Sep 2022, 5:51 PM
Gargi Chandrababu
Gargi Chandrababu - avatar
- 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 šŸ™
15th Jan 2023, 4:05 PM
Odoi Yona
Odoi Yona - avatar
- 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
12th Oct 2020, 12:07 PM
Agboola Vincent
Agboola Vincent - avatar