~ Solve Problems and Learn how to code in Python


5 - String Manipulation - Email Creator based on a validated username

Challenge - use string manipulation techniques to solve this problem

First, watch the demo video below. Your task is to code something like this, and use the code below to get started

Code Challenge

You can edit the code below in repl.it. Alternatively, you can simply cut and paste the below into your own python file

#RUN THE PROGRAM and see what it does
#this is not how validation for email works. It usually does NOT allow spaces

#**************Task: The generated email should be in the following format:
#the input MUST be lower case
#the input must contain digits
#If the input is: johnnysmith  >> email should be: [email protected]
#if the input is: marthajones >> email should be [email protected]

"""
A FEW IMPORTANT COMMANDS 
word.isalnum()         #check if all char are alphanumeric 
word.isalpha()         #check if all char in the string are alphabetic
word.isdigit()         #test if string contains digits
word.istitle()         #test if string contains title words
word.isupper()         #test if string contains upper case
word.islower()         #test if string contains lower case
word.isspace()         #test if string contains spaces
word.endswith('d')     #test if string endswith a d
word.startswith('H')   #test if string startswith H

"""

def hasSpace(username): #this is a little function that takes the paramater username
   return any(char.isspace() for char in username) #this returns TRUE if any character in username includes a space


def main():
   print("*************************** Create an e-mail address*********************")
   print("***************************                                               ********************** ")
   username=input("Please enter your desired username:" )
   
   if username.islower() and hasSpace(username): #if the username is lowercase and IF the function hasNumbers returns True then....do the folllwing
         email=username+"@gmail.com"
         print("Your unique email address is now:", email)
   else:
         print("Your username needs to be lower case and have spaces...............")
main()

Code your solution here

Systems Life Cycle (in a nutshell): Analyse - Design - Create - Test - Evaluate. Designing something or writing out some pseudocode before you actually write code is always a good idea! Get in to the habit of doing so! You can draw your flowchart here and screenshot it.

A sample flow chart (design) for this particular challenge could look like:

Flowchart: Python program to get the Fibonacci series between 0 to 50
Each challenge section below provides an online drawing tool where you can dynamically create flowcharts. Screenshot them into your presentation for submission.

Solutions & Answers

Answers /Solutions in the "members area" drive under: "Solve and Learn >>SOLUTIONS"

Testing Table

You may want to read a little about Testing first. A teacher may go through some examples with you. Feel free to fill in the test table here, and screenshot it in to your powerpoint. Testing is absolutely essential once you have created a program!
Test No. Description Test Data(input) Expected Outcome Actual Outcome Further Action?
1
2
3
4
5
Coming soon!