input() pauses your program and waits for the user to type something and press Enter. Whatever they type is handed back as a string, which you usually save in a variable.
name = input("What is your name? ")
print(f"Nice to meet you, {name}!")
The text inside input("...") is the prompt โ the question shown to the user.
๐ฅ๏ธ In this playground
When your code reaches input(), a small pop-up box appears. Type your answer there and press OK. Try it in the Practice tab!
โ ๏ธ input() always gives you text
Numbers from input are strings!
Even if the user types 7, input() returns the string"7". To do math, you must convert it with int() or float().
age = input("How old are you? ")
age = int(age) # convert text to a number
print(f"Next year you'll be {age + 1}")
input("prompt") waits for the user to type something.
It always returns a string.
Wrap it in int() or float() to get a number.
๐ฎ Time to Practice!
When you press โถ Run, a pop-up will ask you to type. These tasks are interactive โ just press โถ Run and play!
๐
Task 1: Friendly Greeter
Easy
Ask the user their name, then greet them by name. Press โถ Run and type your name in the pop-up.
๐
Task 2: Age Next Year
Medium
Ask the user their age, convert it to a number, and tell them how old they'll be next year. Remember: convert with int() before adding 1!
age = int(input("How old are you? "))
print(f"Next year you will be {age + 1}!")
โ
Task 3: Two-Number Adder
Tricky
Ask for two numbers and print their sum. Be careful โ convert both inputs to numbers, or Python will glue the text together instead of adding!
a = int(input("First number: "))
b = int(input("Second number: "))
print(f"The sum is {a + b}")
๐
Task 4: Free Play โ Mad Libs!
Creative
Build a silly story! Ask for an animal, a color, and an action, then drop them into a funny sentence. Run it and laugh. ๐
๐๏ธ Extra Practice โ Interactive Drills
These programs talk to you. Press โถ Run, answer the pop-ups, and watch what your code does with your answers. Try running each one twice with different answers!
๐ฐ
Task 5: Birthday Countdown
Easy
Ask for the user's name and their age, then print a sentence saying how many years until they turn 100. Remember to wrap the age in int().
name = input("Your name: ")
age = int(input("Your age: "))
print(f"Hi {name}! You will turn 100 in {100 - age} years.")
๐
Task 6: Rectangle Room
Easy
Ask for the width and length of a room in meters (they may be decimals โ use float()), then print the area and the perimeter.
Ask for a word, then print: how many letters it has, the word in CAPITALS, the word reversed, and its first letter.
word = input("Type a word: ")
print(f"Letters: {len(word)}")
print(word.upper())
print(word[::-1])
print(f"First letter: {word[0]}")
๐
Task 8: Party Planner
Medium
Ask how many guests are coming and how many slices of cake each guest eats. Print the total slices needed, and how many whole cakes to buy if one cake has 8 slices (round up by adding 7 before dividing โ a classic trick!).
guests = int(input("How many guests? "))
slices = int(input("Slices per guest? "))
total = guests * slices
print(f"You need {total} slices")
print(f"Buy {(total + 7) // 8} cakes")
๐ก๏ธ
Task 9: Temperature Translator
Medium
Ask for a temperature in Celsius and print it in Fahrenheit. The formula is F = C * 9 / 5 + 32. Show the answer with one decimal place using {value:.1f}.
celsius = float(input("Temperature in Celsius: "))
print(f"{celsius}ยฐC is {celsius * 9 / 5 + 32:.1f}ยฐF")
๐
Task 10: Password Checker
Medium
Ask the user to invent a password. Print how long it is, and print Strong ๐ช if it is 8 characters or more, otherwise Too short ๐ฌ. (You'll meet if properly in the next lesson โ try it here anyway!)
password = input("Invent a password: ")
print(f"Length: {len(password)}")
if len(password) >= 8:
print("Strong ๐ช")
else:
print("Too short ๐ฌ")
๐งฎ
Task 11: Boss Level: Shopping Till
Boss
Ask for an item name, its price, and how many the customer wants. Then print a tidy receipt: the item line with the total, a 10% tax line, and the final amount โ all with 2 decimal places.
Write a bot that asks the user at least four questions (favorite animal, dream job, lucky number, best foodโฆ) and then prints a funny paragraph about them using every answer. ๐ค