Create an Astronaut Name Tag Processor

PythonBeginner
Practice Now

Introduction

As a new recruit at the LabEx Space Academy, you have been tasked with creating a simple program to process astronaut name tags. This challenge will test your ability to manipulate strings in Python, a crucial skill for handling text data in various space mission scenarios.

This is a Challenge, which differs from a Guided Lab in that you need to try to complete the challenge task independently, rather than following the steps of a lab to learn. Challenges are usually a bit difficult. If you find it difficult, you can discuss with Labby or check the solution. Historical data shows that this is a beginner level challenge with a 92% pass rate. It has received a 98% positive review rate from learners.

Astronaut Name Tag Processor

In this step, you will create a Python script that processes an astronaut's name to create a standardized name tag.

Tasks

  • Create a Python script named name_tag_processor.py in the /home/labex/project directory. (Recommend to use WebIDE)
  • Use the input() function to prompt the user to enter an astronaut's full name.
  • Process the entered name to create a standardized name tag by performing the following operations:
    1. Convert the full name to uppercase using the upper() method
    2. Replace any spaces with underscores using the replace() method
    3. Add the prefix "ASTRONAUT_" to the beginning of the processed name.
  • Print the original name and the processed name tag.

String Methods Reference

upper()

The upper() method converts all characters in a string to uppercase:

name = "John Doe"
uppercase_name = name.upper()  ## Returns "JOHN DOE"

replace()

The replace() method replaces all occurrences of a substring with another substring:

name = "John Doe"
name_with_underscores = name.replace(" ", "_")  ## Returns "John_Doe"

Requirements

  • The script must be named name_tag_processor.py and located in the /home/labex/project directory.
  • Use the string methods upper() and replace() as shown in the examples above.
  • The script should run without any errors and prompt the user for input.
  • The output should display both the original name and the processed name tag.

Example

After finishing the challenge, open the WebIDE terminal (Top Menu bar -> Terminal -> New Terminal) and run the script.

python3 name_tag_processor.py
Astronaut name tag example

You will see the following output:

Enter astronaut's full name: John Doe
Original name: John Doe
Processed name tag: ASTRONAUT_JOHN_DOE
✨ Check Solution and Practice

Summary

In this challenge, you have created a Python script to process astronaut name tags. This exercise has reinforced your understanding of string manipulation in Python, including methods like upper() and replace(). You have also practiced using the input() function to get user input and formatting output strings. These skills are fundamental in Python programming and will be valuable in more complex data processing tasks you may encounter in your space academy training.