Project Overview 💡
In this project, you’ll practice basic string manipulations in Python. You’ll ask the user for their full name, then perform various operations like converting to uppercase/lowercase, removing spaces, counting characters, and reversing the name.
Challenge Yourself! 🚀
Before checking the solution, try to solve the task of this project on your own!
Task:
Write a Python program that:
Accepts a user's full name as input
Prints the name in uppercase and lowercase
Removes spaces and counts the characters
Reverses the name
Expected Output: Here is how the program would work. The program asks the user to enter their name (e.g., user enters “John Smith”) and then prints out the output.
Give it a shot! Scroll down when you're ready for the step-by-step guide.
Spoiler Alert!
Step-by-Step Guide
Step 1️⃣: Get User Input
Ask the user to input their full name.
Place this code in line 1-2:
# Get the user's full name
full_name = input("Please enter your full name: ")
Step 2️⃣: Display the Name in Uppercase
Convert the string to uppercase using .upper()
.
Place this code in line 4-5:
# Display the name in uppercase
print("Your name in uppercase:", full_name.upper())
Step 3️⃣: Display the Name in Lowercase
Convert the string to lowercase using .lower()
.
Place this code in line 7-8:
# Display the name in lowercase
print("Your name in lowercase:", full_name.lower())
Step 4️⃣: Remove Spaces and Count Characters
Remove all spaces using .replace()
and count the characters using len()
.
Place this code in lines 10-12:
# Remove spaces and count the total number of characters
name_no_spaces = full_name.replace(" ", "")
print("Total number of characters (excluding spaces):", len(name_no_spaces))
Step 5️⃣: Reverse the Name
Use slicing to reverse the string.
Place this code in lines 14-16:
# Reverse the name
reversed_name = full_name[::-1]
print("Your name reversed:", reversed_name)
Complete Code 🧨
# Get the user's full name
full_name = input("Please enter your full name: ")
# Display the name in uppercase
print("Your name in uppercase:", full_name.upper())
# Display the name in lowercase
print("Your name in lowercase:", full_name.lower())
# Remove spaces and count the total number of characters
name_no_spaces = full_name.replace(" ", "")
print("Total number of characters (excluding spaces):", len(name_no_spaces))
# Reverse the name
reversed_name = full_name[::-1]
print("Your name reversed:", reversed_name)
Alternative Solution
Here's a version using a function to group all string manipulations:
def analyze_name(name):
print("Your name in uppercase:", name.upper())
print("Your name in lowercase:", name.lower())
print("Total number of characters (excluding spaces):", len(name.replace(" ", "")))
print("Your name reversed:", name[::-1])
full_name = input("Please enter your full name: ")
analyze_name(full_name)
Comparison
The original version does each operation directly in sequence.
The alternative version groups logic inside a function — better for reuse and organization. Using functions is better for more complex programs. For our program, the original version is optimal.
Want More? 🔥
Enjoyed this project? Unlock real-world projects with full guides & solutions by subscribing to the paid plan. 🎉