Gamertag

Gamertag

Creating a new user account.

A gamertag is a persona used to identify players in online games. A gamertag can include letters, numbers and symbols, but no two players can share the same gamertag. This program allows a player to enter their preferred gamertag and prevent other players from claiming it.

Make


Write a program that asks the user to enter a gamertag. If the gamertag already exists in a file an error message is output, otherwise the gamertag is appended to the file.

Use this boilerplate code as a starting point:

Success Criteria

Remember to add a comment before a subprogram, selection or iteration statement to explain its purpose.

Complete the subprogram called `check_exists` that:

  1. Takes a parameter that is the gamertag.
  2. Attempts to open a file called, `players.txt` for reading data. Note the file is included in the Trinket above for you to use as source data.
  3. Checks to see if the gamertag exists in the file.
  4. Returns True if it does and False if it does not.

Complete the subprogram called `write_gamertag` that:

  1. Takes a parameter that is the gamertag.
  2. Opens a file called, `players.txt` for appending data.
  3. Writes the gamertag to the file.

Complete the subprogram called `get_gamertag` that:

  1. Asks the user to enter their chosen gamertag.
  2. Calls, the `check_exists` function to determine if the gamertag is already taken.
  3. If the gamertag has already been taken it outputs a message, “Sorry, that gamertag is already taken. Try again.”
  4. If the gamertag has not already been taken it calls, `write_gamertag` to record the gamertag.
  5. Outputs a confirmation message.

Complete the `main program` so that:

  1. It calls the `get_gamertag` subprogram.

Typical inputs and outputs from the program would be:

`players.txt` file:

FluidYosta

IdolizedMero

TimotheosDark

DemonCamping

Enter your chosen gamertag: DemonCamping

Sorry, that gamertag is already taken. Try again.

Enter your chosen gamertag: DemonRushing

Welcome DemonRushing


Enter your chosen gamertag: OnlyUseMePistol

Welcome OnlyUseMePistol

Knowledge Organiser

Use these resources as a reference to help you meet the success criteria.

Programming guide:

Evaluate


Run the unit tests below to check that your program has met the success criteria.

Remember to reset the data file if your program successfully writes data to the file before running the unit tests.

Enter your chosen gamertag: IdolizedMero

Sorry, that gamertag is already taken. Try again.

Enter your chosen gamertag: FluidYosta

Sorry, that gamertag is already taken. Try again.

Enter your chosen gamertag: DesperateDan

Welcome DesperateDan

Check that you have:

  • Used comments within the code to describe the purpose of subprograms, conditions and iterations.
  • Used meaningful identifier names. That means the names of subprograms and variables indicate what they are for.
Craig'n'Dave logo

Craig ‘n’ Dave

Bett Awards 2024 Finalist