Lab Activity: My First Python Program
Task:
Write a Python program that asks the user for their name, age, and favourite number.
The program should:
-
Store the values in variables.
-
Display the data types of each variable.
-
Do a simple calculation with the favourite number (e.g., multiply it by 2).
-
Print a personalized message using string concatenation and string methods.
Example Solution:
# Step 1: Take input from user
name = input("Enter your name: ")
age = int(input("Enter your age: "))
fav_num = float(input("Enter your favorite number: "))
# Step 2: Show data types
print("Data Types:")
print("Name:", type(name))
print("Age:", type(age))
print("Favorite Number:", type(fav_num))
# Step 3: Perform a calculation
double_num = fav_num * 2
# Step 4: Print personalized message
print("Hello " + name.upper() + "!")
print("You are", age, "years old.")
print("Your favorite number doubled is:", double_num)
Expected Output (Sample Run):
Enter your name: Alice
Enter your age: 20
Enter your favorite number: 7
Data Types:
Name: <class 'str'>
Age: <class 'int'>
Favorite Number: <class 'float'>
Hello ALICE!
You are 20 years old.
Your favorite number doubled is: 14.0
This activity reinforces variables, data types, operators, input/output, and string methods in one small program.
