The Task
Build a program that:
- Asks the user for their name, age, city, and height in feet.
- Prints a profile card with those details.
- Shows the user’s age next year.
What You’ll Use
input()to take information from the user.int()andfloat()to convert input into numbers.- Variables to store values.
print()to display the result.\nto add spacing.- Comments to explain the code.
Expected Output
Enter your name: John
Enter your age: 27
Enter your city: Delhi
Enter your height in feet: 5.9
--- Profile Card ---
Name: John
Age: 27
City: Delhi
Height: 5.9 ft
Next year, you will be 28Try It Yourself First
Give it a try before you scroll down.
Here’s a hint for each part:
input()always returns a string.- Age needs to be a whole number, so use
int(). - Height can have decimals, so use
float(). - To calculate next year’s age, add
1to the age.
Solution
# Profile Card
name = input("Enter your name: ")
age = int(input("Enter your age: "))
city = input("Enter your city: ")
height = float(input("Enter your height in feet: "))
print("\n--- Profile Card ---")
print("Name:", name)
print("Age:", age)
print("City:", city)
print("Height:", height, "ft")
print("Next year, you will be", age + 1)How It Works
nameandcitystay as strings, so no conversion is needed.ageis converted withint(), so we can add1to it later.heightis converted withfloat(), since it can have a decimal part.\nat the start of"\n--- Profile Card ---"adds an empty line before the card.age + 1gives us next year’s age.
Common Mistake
If you forget int() when taking the age:
age = input("Enter your age: ")
print("Next year, you will be", age + 1)Python raises an error because age is a string, while 1 is a number.
Challenges
If you want to go a little further, try these:
- Add more pieces of information to the profile card.
- Try changing the
sepparameter inprint()and see how it changes the output.
👉 Next tutorial: Python Strings