Hello Alan Lloyd - Your Scores - Logout

Lesson 3: User Input and Basic String Manipulation

Lesson 3: User Input and Basic String Manipulation

This lesson will teach students how to accept user input and manipulate strings. They will write a program that asks for their name and age, then displays a customized greeting. Concepts like string formatting and basic methods (upper(), lower(), strip()) will be introduced.

Introduction

Welcome to Lesson 3! Today, we’re going to make our programs talk to the user and even remember what they say! You’ll learn how to ask questions and play with words in fun ways.

🌟 What You’ll Learn:

  • How to get input from the user

  • What strings are (they’re just text!)

  • How to use string methods like .upper(), .lower(), and .strip()

  • How to make a personalised greeting program

✨ Step 1: Talk to the User

Use input() to ask the user a question and store their answer.

 

Example:

name = input("What is your name? ")
print("Hello, " + name + "!")

Try it! What happens if you enter your name in CAPITALS? Or with spaces before and after?

 



 

✨ Step 2: All About Strings

A string is just a fancy word for text. Python gives you cool tools to change it:

.upper()  # Makes everything BIG
.lower()  # Makes everything small
.strip()  # Removes spaces at the start and end

Example:

text = "   Hello World!   "
print(text.upper())   # "   HELLO WORLD!   "
print(text.lower())   # "   hello world!   "
print(text.strip())   # "Hello World!"

Try This:

word = input("Type a word: ")
print("BIG word:", word.upper())
print("small word:", word.lower())
print("tidy word:", word.strip())


 

 

✨ Step 3: String Magic with f-strings

Python lets you mix text and variables using f-strings. They’re super useful!

Example:

name = "Leo"
age = 11
print(f"Hi {name}, you are {age} years old!")

Try This:

name = input("What's your name? ")
age = input("How old are you? ")
print(f"Nice to meet you, {name}! You're {age} years old.")


 

 

🚀 Let’s Build: A Friendly Greeting Program

Time to create a fun greeting program that uses everything you’ve learned!

print("Hello there! Let's get to know you.")

name = input("What is your name? ").strip()
age = input("How old are you? ").strip()

print("\n--- Greeting ---")
print(f"Hi {name.title()}! Wow, {age} is a great age!")

Challenge: Can you add a message that changes depending on the age?

if int(age) < 10:
    print("You're a young coder in training!")
elif int(age) < 16:
    print("Keep up the great work, future programmer!")
else:
    print("You're a coding superstar!")


 

 

🎉 Well Done!

You’ve learned how to chat with users and make text do what you want. Next time, we’ll dive into maths and logic!

Practice Tip: Try making a mini quiz that asks for the user’s name and answers, then gives feedback using string methods and f-strings.

You’re smashing it, coding champ! 🏆

Summary of This Lesson

✅ How to use input() to ask questions
✅ What strings are and how to use them
✅ String methods like .upper(), .lower(), and .strip()
✅ How to use f-strings to combine text and variables
✅ How to make a personalised greeting program

Next time, we’ll dive into basic maths and operators — you’ll learn how Python adds, subtracts, multiplies and divides, and you’ll build your very own calculator! 🔢💻

Leave a comment


'; // Add header content for print html += '

Lenara Learning

Get more learning resources at www.lenara.uk

'; // Insert the worksheet content html += '
' + content + '
'; html += ''; printWindow.document.write(html); printWindow.document.close(); printWindow.focus(); // Trigger printing and auto-close the popup printWindow.print(); printWindow.onafterprint = function() { printWindow.close(); }; setTimeout(function() { printWindow.close(); }, 1500); }