// Functions
PARAMETERS Mini Project — Username Generator
The problem...
You've built the Username Generator before. It worked — but it was one long script. Top to bottom. No structure. No reuse.
Time to rebuild it the right way.
The idea!
One function. One job. You pass the values in — the function handles the rest. No input() inside. No hardcoded values. Just parameters.
Your mission
Rewrite the Username Generator as a function. Name, year, and prefix as parameters. Default prefix included.
The solution
def generate_username(name, year, prefix="rhd_"):
username = prefix + name.replace(" ", "").lower() + year[-2:]
print(f"Your username is: {username}")
generate_username("Bull", "2001")
generate_username("RedHorn", "2001", "dev_")
Test it
# Your username is: rhd_bull01
# Your username is: dev_redhorn01
What's really happening
Name and year come in as parameters — no input() needed inside the function. The prefix has a default — pass it if you want something different, skip it if rhd_ works. Two calls, two different results, no rewriting.
Go further
- Call the function with your own name and birth year
- Try different prefixes —
"dev_","usr_","x_" - Add a fourth parameter for a favorite number — append it to the username
What you should understand now
- Parameters replace hardcoded values — pass what changes, keep what stays
- Default parameters —
prefix="rhd_"— optional but always available - No
input()inside — the function receives values, it doesn't ask for them - Same function, different arguments — different result every time
// resources
// 0 comments
// No comments yet. Be the first.
// leave a comment