CodeSolved

Solved Programming Questions & Exercises

Separation of email sections

Practice Easy 40/ Download 1221 Views

Write a program that receives an email address and separates the various sections as follows and prints on the output

Example:

email: info@amirhn.ir
info
amirhn.ir

Example:

email: username@gmail.com
username
gmail.com 

15 Answers

This answer is only visible to premium members
This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error'
alert(msg) 
This answer is only visible to premium members
This answer is only visible to premium members

This answer is only visible to premium members

Subscription is currently unavailable.
This answer is only visible to premium members
This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error'
alert(msg) 
This answer is only visible to premium members
This answer is only visible to premium members

This answer is only visible to premium members

Subscription is currently unavailable.
This answer is only visible to premium members
This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error'
alert(msg) 
This answer is only visible to premium members
This answer is only visible to premium members

This answer is only visible to premium members

Subscription is currently unavailable.
email = input("enter email: ")
username, domain = email.split("@")
print(f"{username}\n{domain}")
def split_email(email):
    try:
        username, domain = email.split('@')
        return username, domain
    except ValueError:
        return "email na motabar"
email = input("email: ")
result = split_email(email)
if isinstance(result, tuple):
    print(f"username: {result[0]}")
    print(f"damin: {result[1]}")
else:
    print(result)
email=input("please enter your email: ")
atsinChar=email.find("@")
print(email[:atsinChar])
print(email[atsinChar+1:])
Saeeda33 Download Python
i = input("Enter Email :")
f = i.find("@")
s = i[:f]
s2 = i[f+1:]
print(f"Email Shom:{i}\n User Email Shoma:{s}\n Damein Email Shoma:{s2}")
e = str(input("mail: "))
a = e .find("@")
print(e[:a])
print(e[(a + 1):])
User 3026 Download Python
# Color code
RED = '\033[91m'  # Red
LIGHT_RED = '\033[38;5;160m'  # Reddish -orange
GREEN = '\033[92m'  # Green
PURPLE_LIGHT = '\033[38;5;141m'  # Purple much brighter
GRAY = '\033[90m'  # Light gray
YELLOW = '\033[93m'  # Golden
PINK = '\033[95m'  # Pink
RESET = '\033[0m'  # Reset color to default

attempts = 6  # The number of times allowed to enter the email

# Loop to request email from the user, with the limit of the number of attempts
while attempts > 0:  # The loop continues until the number of attempts is greater than 1
    email = input("Enter email: ")  # Receive email from user
    
    # Check that the email must contain only one @
    if "@" in email and email.count("@") == 1:
        x = email.find("@")  # Find the position of the first @ in the email string
        before = email[:x]  # Get the pre - @ section (username)
        after = email[x:]   # Getting the section includes @ and domain (from @ to next)

        # Check that there must be at least one point (.) After @
        if before and after.count(".") >= 1:
            # Find the position of last point (.) On the domain
            last_dot = after.rfind(".")  # Find the position of last point (.) On the domain
            # Part of @ until the last point (which includes a slope without extension)
            domain_with_at = after[:last_dot]  
            # Domain extension that is located after the last point
            extension = after[last_dot+1:]  

            # Check that the domain and extension are valid
            if domain_with_at and extension and len(extension) >= 2:
                # Printing Username in Light Gray
                print(f"Text: {GRAY}{before}{RESET}")  
                # Green Domain Printing
                print(f"Domain: {GREEN}{domain_with_at}{RESET}")  
                # Printing of a light gray extension extension
                print(f"Extension: {GRAY}{extension}{RESET}")  
                
                # Complete Complete Email correctly
                # Before @ (username) + @ + domain +. + Domain extension
                full_email = before + "@" + domain_with_at + "." + extension  
                
                # Full email printing with correct coloring:
                # Username to gray, domain to green and extension to gray
                print(f"Full Email: {GRAY}{before}{RESET}{GREEN}@{domain_with_at}{RESET}.{GRAY}{extension}{RESET}")  
                break  # Exit the loop if the email is correct

    # If the email entered is wrong, the number of attempts will be reduced
    attempts -= 1  # Reduce the number of attempts after any invalid entry
    
    # If the number of residual efforts is greater than 1, the error message will be displayed in gold
    if attempts > 3:
        print(f"{YELLOW}The email structure is incorrect. Try again.{RESET}")
    
    # If the number of residual efforts is less or equal to 1, the warning message is very bright with the number of residual purple efforts.
    if 0 < attempts <= 3:
        print(f"{PURPLE_LIGHT}Try again... {RED}⚠️{attempts} attempts left⚠️{RESET}") 

# If the number of attempts reaches 1, the exit message will be displayed in pink
if attempts == 0:
    print(f"{PINK}your deadline has expired...{RESET}")
Azhgun Download Python
a=(input('email:'))
s=a.find('@')
print(a[:s] )
print(a[s:])
Maryam.n Download Python
<< Previous page 1 2 Next page >>

Submit answer

Submitting answers is currently unavailable.

Related content

Detection using AI
×
×
Close