×
Samples Blogs Make Payment About Us Reviews 4.9/5 Order Now

Create An Email Validation Using Regular Expression in The Python Assignment Solution

June 29, 2024
Dr. Victoria Campbell
Dr. Victoria
🇬🇧 United Kingdom
Python
Dr. Victoria Campbell holds a Ph.D. in Computer Science from a leading university in the UK and has completed over 800 assignments related to Python file handling. With a passion for teaching and research, Dr. Campbell specializes in complex data manipulation, optimization algorithms, and machine learning applications in Python. Her expertise includes text file parsing, CSV data processing, and implementing advanced error handling mechanisms.
Key Topics
  • Instructions
    • Objective
  • Requirements and Specifications
Tip of the day
Use the REPL (Read-Eval-Print Loop) to test your code interactively, and practice writing concise, readable expressions to harness Scala’s powerful syntax effectively.
News
In 2024, JavaScript's Redux saw updates for efficient state management, and Tailwind CSS gained traction for responsive design. Meanwhile, C++ libraries like Boost.

Instructions

Objective

Write a python assignment program to create an email validation using regular expression.

Requirements and Specifications

Create-an-email-validation-using-regular-expression-in-python
Create-an-email-validation-using-regular-expression-in-python 1

Screenshot

Create-an-email-validation-using-regular-expression-in-python 2

Source Code

TASK 1 def factorial(n): # starting with value 1 result = 1 # keep multiplying by consecutive integers including n for i in range(n): result *= (i + 1) return result def main(): # keep asking user until nonnegative value is entered while True: n = int(input('Please input a nonnegative integer? ')) if n >= 0: # calculating factorial of given integer print('Factorial of', n, ':', factorial(n)) return else: # showing error message print('Please enter a nonnegative integer') print() if __name__ == '__main__': main() TASK 2 def factorial(n): # if n == 0, returning 1 if n == 0: return 1 # returning result as a product of (n-1)! and n return factorial(n-1) * n def main(): # keep asking user until nonnegative value is entered while True: n = int(input('Please input a nonnegative integer? ')) if n >= 0: # calculating factorial of given integer print('Factorial of', n, ':', factorial(n)) return else: # showing error message print('Please enter a nonnegative integer') print() if __name__ == '__main__': main() TASK 3 import re def check_email(email): # using following regex: # - positive number of symbols: alphanumeric/-/. # - single @ # - positive number of symbols: alphanumeric/-/. regex = '^[\w\-.]+[@][\w\-.]+$' if re.search(regex, email): # if email matches pattern, searching for index of '@' idx = email.index('@') # returning separated username and host, as a tuple return email[:idx], email[idx+1:] # if valid is not valid, returning None return None def main(): # keep asking user until value email is entered while True: result = check_email(input('Please input your email address:').strip()) if result: # outputting result of email parsing print('email: ', result[0] + '@' + result[1], ',', 'username: ', result[0], ',', 'host: ', result[1]) return else: # showing error message print('Not a valid email.') print() if __name__ == '__main__': main()

Similar Samples

Discover our sample programming assignments at ProgrammingHomeworkHelp.com. These exemplify our dedication to delivering top-notch solutions across various languages and complexities. Each sample demonstrates our proficiency in problem-solving and adherence to quality standards, ensuring your academic or professional programming needs are met with excellence.