Search for question
Question

Lab Exercises: NOTE: All solutions MUST use the Python regular expression module: re ALSO: The website https://regex101.com may be used and will offer significant help and insight into the of your regular expressions. creation Lab 3 1. Write a Python function to validate a credit card number as follows: The card number MUST BE exactly 13 or 16 digits in length and may ONLY be entered as xxx×××××××××x OR xxxx xxx xxx xxx OR xxxx-xxx-xxx-xxx OR ×××××××××××××××x OR xxxx xxxx xxxx xxxx OR xxxx-xxxx-xxxx- XXXX The function prototype MUST be: def validateCard (cardNum) : and returns true if the card number is valid and false otherwise. 2. Write a Python function that validates e-mail addresses as follows: Only the following characters are permitted: Uppercase (A-Z), lowercase (a-z), digits (0-9), and '@'. The e-mail format MUST be username@host.domain where only a single '@' MUST be present (between the username and the host). The username may only contain alphanumeric characters and must contain a minimum of 2 alphanumeric characters, with the first character being alphabetic. The host must contain a minimum of 2 alphanumeric characters ONLY and also may only contain alphanumeric characters. The domain must contain a minimum of 2 (but no more than 4) alphabetic characters ONLY. The function prototype MUST be: def validateEmail (email) : and returns true if the e-mail address is valid or false otherwise. 3. Write a Python function that accepts a string of text and removes all duplicate spaces (2 or more) and replaces them with a single space. This regular expression also removes leading and trailing spaces. If a string containing all spaces is submitted, then your code would return an empty string. The function prototype MUST be: def cleanString (textStr) and returns a copy of the modified string. : 4. Write a python function to convert a snake case string to a camel case string such that the snake character snake case: speed_of_light infix_to_postfix area_in_meters joined with each subsequent word being initially capitalized. (see examples below): I 1 MAIN PROGRAM: is removed and the following text is The function prototype MUST be: def snakeToCamel (s) : and returns a copy of the modified string. NOTE: Your solution MUST use regular expressions and their related functions ONLY. import string import re camel case: speed0fLight infixToPostfix areaInMeters #Your solution may ONLY use the python modules listed below # program: L3main.py #author: danny abesdris # date: february 19, 2024 #purpose: python main() program for PRG550 Winter 2024 Lab #3 # YOUR CODE BELOW... def validateCard (cardNum) : def validateEmail (email) : def cleanString (textStr) : def snakeToCamel (s) : def main() : # invalid #valid print (validateCard ("1234567890ABC")) print (validateCard ("1234567890123")) print (validateCard ("123 456 789 0123")) print (validateCard ("1234 567 890 ABC")) print (validateCard ("1234-567-890-123")) print (validateCard ("1234-5678-9012-3456")) # valid # invalid # invalid #valid print (validateCard ("1234567890123456")) print (validateCard ("123456789012345")) print ("---▬▬") # valid #invalid print (validateEmail ("student@seneca.ca")) print (validateEmail ("a@google.com")) print (validateEmail ("abc.@host.cars")) print (validateEmail ("name.host.com")) print (validateEmail("first.last@abc.ca")) print (validateEmail ("my.last@abc.c@a")) print (validateEmail ("my.last@abcca")) print (validateEmail ("abc@google.com")) print (validateEmail ("_abc@google.com")) #valid # invalid # invalid # invalid # invalid # invalid # invalid # valid #invalid print (validateEmail ("abc@google.comms")) #invalid print ("---▬▬") print (cleanString (" This is print (cleanString ("A good string")) print (cleanString (" print (cleanString (" print (cleanString ("no-spaces-at-all")) if name main () print ("---▬▬") print (snakeToCamel ("speed_of_light_in_meters_squared")) print (snakeToCamel ("infix_to_postfix")) print (snakeToCamel ("alreadyInCamelCase")) # end main() True False False False False False False True False False == "I ‒‒‒‒‒ The OUTPUT should be EXACTLY as displayed below: False True False False True True True False This is a string A good string Where do you want to go? no-spaces-at-all main infixToPostfix a string Where do you want to go?")) ")) : speedOfLightInMetersSquared already InCamelCase "))