Python Notes Part 1: Input, Output & Variables:
What is a Program?
A program takes input, does some work, and gives output.
For example:
A calculator takes numbers (input), does math (process), and shows the answer
(output).
Showing Output – print()
Use the print() command to show text or numbers on the screen.
print("Welcome!") # Output: Welcome!
print("My name is") # Output: My name is
print(25) # Output: 25
print("years young.") # Output: years young.
Note:
Put text in quotes " "
Numbers don’t need quotes
Getting Input – input()
Use the input() command to ask the user to type something.
Save that input into a variable.
print("What is your favourite fruit?")
# Output: What is your favourite fruit?
fruit = input() # User types: mango
You can also ask and store in one line:
fruit = input("What is your favourite fruit? ")
# Output: What is your favourite fruit?
# User types: mango
GCSE/IGCSE Computer Science Python Notes 1
Showing a Message with User Input
your_name = input("Type your name: ") # Output: Type your name:
User types: Ayaan
print("Nice to meet you,", your_name)
# Output: Nice to meet you, Ayaan
What Are Variables?
Variables are like boxes that hold data.
Example:
age = 16
Now, age holds the number 16.
Rules for variable names:
Use one word, like userName or user_age
Don’t use Python keywords like print, input
Start with small letters
Input with Data Types
Use data types to make sure the input is stored correctly:
city = str(input("Where do you live? "))
# Output: Where do you live?
# User types: Karachi
timeNow = int(input("What hour is it? "))
# Output: What hour is it?
# User types: 14
weather = float(input("What is the temperature? "))
# Output: What is the temperature?
# User types: 34.5
print("In", city, "it is", weather, "degrees at", time now,
"o'clock.")
# Output: In Karachi it is 34.5 degrees at 14 o'clock.
GCSE/IGCSE Computer Science Python Notes 2
Combining (Joining) Text – Concatenation
first = input("Enter your first name: ")
# Output: Enter your first name:
# User types: Sara
last = input("Enter your last name: ") # Output: Enter your last
name:
# User types: Ali
print(first + " " + last) # Output: Sara Ali
print(first + last) # Output: SaraAli
Summary Table
Task Code Example Output Example
Show message print("Hello") Hello
Get input name = input("What is your name? ") What is your name? → Ayaan
Save a number age = int(input("How old are you? ")) How old are you? → 18 (saved as int)
Show variables print("You are", age, "years old") You are 18 years old
Join words print(first + " " + last) Sara Ali
GCSE/IGCSE Computer Science Python Notes 3