•Write a regular expression for both a zip code and a phone number in python.
1> We need to validate a ZIP code (U.S. postal code), allowing both the five-digit and nine-digit (called ZIP+4) formats. The regex should match 12345 and 12345-6789, but not 1234, 123456, 123456789, or 1234-56789.
Regular expression:
^[0-9]{5}(?:-[0-9]{4})?$
=> To understand the regular expression:
^ # Assert position at the beginning of the string. [0-9]{5} # Match a digit, exactly five times. (?: # Group but don't capture: - # Match a literal "-". [0-9]{4} # Match a digit, exactly four times. ) # End the noncapturing group. ? # Make the group optional. $ # Assert position at the end of the string.
2> Let say, you want to validate & format north americans phone numbers, then you need to determine whether a user entered a North American phone number, including the local area code, in a common format. These formats include 1234567890, 123-456-7890, 123.456.7890, 123 456 7890, (123) 456 7890, and all related combinations. If the phone number is valid, you want to convert it to your standard format, (123) 456-7890, so that your phone number records are consistent.
^\(?([0-9]{3})\)?[-.●]?([0-9]{3})[-.●]?([0-9]{4})$
^ # Assert position at the beginning of the string. \( # Match a literal "(" ? # between zero and one time. ( # Capture the enclosed match to backreference 1: [0-9] # Match a digit {3} # exactly three times. ) # End capturing group 1. \) # Match a literal ")" ? # between zero and one time. [-. ] # Match one hyphen, dot, or space ? # between zero and one time. ⋯ # [Match the remaining digits and separator.] $ # Assert position at the end of the string.
3> if you need to validate international phone numbers. The numbers should start with a plus sign, followed by the country code and national number.
^\+(?:[0-9]●?){6,14}[0-9]$
^ # Assert position at the beginning of the string. \+ # Match a literal "+" character. (?: # Group but don't capture: [0-9] # Match a digit. \x20 # Match a space character ? # between zero and one time. ) # End the noncapturing group. {6,14} # Repeat the group between 6 and 14 times. [0-9] # Match a digit. $ # Assert position at the end of the string.
•Write a regular expression for both a zip code and a phone number in python.
Python Write a program that asks the user for a zip code and converts it to a postal bar code. A postal bar code uses two types of lines long and short. Since we can't print "long line” we will use: 0 - short line 1 - long line. The digits are represented by bars as explained in the below chart Value Encoding 1 00011 2 00101 00110 01001 01010 01100 10001 8 10010 9 10100 0 11000 The bar...
PYTHON 3. Write code using zip and filter so that these lists (l1 and l2) are combined into one big list and assigned to the variable opposites if they are both longer than 3 characters each. l1 = ['left', 'up', 'front'] l2 = ['right', 'down', 'back']
Write a code using python to make an Agenda that can store values such as Name, Address and Phone number of 10 digits Name format First, Last Address Format Street, Number Zip City ST. Country phone format (###) ###-#### This program should give the option of adding a new contact or Display all the contacts you have stored by typing New Contact or Display Contacts
write a regular expression in python (nltk) that will find strings using integers, additon, and multiplication, such as 5*5+8.
write a python software with the following Input The name and phone number for a contact Output The contents of the list after the contact has been added to the list. Processing • Welcome the user to the contact storage software. • Create 2 empty lists: one for names and one for phone numbers. Ask the user to enter the name and phone number of one new contact. Append the newly entered name to the nameList. Append the newly entered...
PYTHON: Write an expression that will cause the following code to print "18 or less" if the value of user_age is 18 or less. Write only the expression. Sample output with input: 17 18 or less
What will the code look like for this? (Python) Write an expression that executes the loop body as long as the user enters a non-negative number. Note: If the submitted code has an infinite loop, the system will stop running the code after a few seconds and report "Program end never reached." The system doesn't print the test case that caused the reported message. Sample outputs with inputs: 9 5 2 -1 Body Body Body Done.
Preliminaries For this lab you will be working with regular expressions in Python. Various functions for working with regular expressions are available in the re module. Fortunately, Python makes it pretty easy to check if a string matches a particular pattern. At the top of the file we must import the re module: import re Then we can use the search() function to test whether a string matches a pattern. In the example below, the regular expression has been saved...
PYTHON CODE Given that play_list has been defined to be a list, write an expression that evaluates to a new list containing the elements at index 0 through index 4 play_list. Do not modify play_list.
Write robust python code that take from the user the name of file to open. Then, take name from the user to search inside the file then display its phone number if found