What’s My Username?

Learning objectives


In this challenge we will use string manipulation techniques to manipulate text data.
In Python a String is a piece of text. It can contain letters, numbers and punctuation signs.

Hello my name is Bond, James Bond

Look at the following code which highlights some key string manipulation techniques:

Using the code above can you tell how to use Python to:

  • Prompt the user to enter their firstname?
  • Concatenate two strings together to create a longer string?
  • Retrieve the first character of a string?
  • Convert a string to uppercase?
  • Calculate the length (number of characters) of a string?
  • Convert a number into a string?

login

Challenge:


Write a program that asks the end-user to enter the following information:

  • Firstname
  • Lastname
  • Year Group

The program should then generate the end-user’s username using the following rules:

  • 2-digit year group + first letter of firstname + lastname
  • The username should be all lowercase
  • If the year group is in 1 digit only (e.g.: 7) then add a “0” in front to make it two digits e.g. “07”

Test your program with the following data:

Firstname Lastname Year Group Expected Output Actual Output
John Lennon 7 07jlennon
Paul McCartney 11 11pmccartney
George Harrison 8 08gharrison
Ringo Starr 9 09rstarr
unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

Did you like this challenge?

Click on a star to rate it!

Average rating 3.3 / 5. Vote count: 3

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!