You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Programs interact with the user through input (receiving data) and output (displaying data). This lesson covers how to read data from a user, display results, and format output — all essential skills for GCSE Computer Science (AQA 3.2 / OCR J277 2.2).
Output is how a program communicates results to the user, typically by displaying text on the screen.
OUTPUT "Hello, World!"
OUTPUT "Your score is: ", score
print("Hello, World!")
print("Your score is:", score)
You can output multiple items by separating them with commas. Python adds a space between items automatically.
You can join (concatenate) strings to build a message:
name = "Alice"
print("Welcome, " + name + "!")
# Output: Welcome, Alice!
When concatenating, all parts must be strings. Use str() to convert numbers:
score = 85
print("Your score is " + str(score))
Alternatively, use f-strings (formatted string literals) in Python 3.6+:
print(f"Your score is {score}")
Input is how a program receives data from the user, typically via the keyboard.
name ← USERINPUT
OUTPUT "Enter your age:"
age ← USERINPUT
AQA pseudocode uses USERINPUT to represent keyboard input.
name = input("Enter your name: ")
age = input("Enter your age: ")
Important: In Python,
input()always returns a string. If you need a number, you must cast the result.
age = int(input("Enter your age: "))
height = float(input("Enter your height in metres: "))
flowchart LR
U[User] -->|types text| K[Keyboard]
K --> I[input / USERINPUT]
I --> V["Variable<br/>always a string"]
V --> C["Cast int / float<br/>if numeric needed"]
C --> P[Process / Calculate]
P --> O[print / OUTPUT]
O --> S[Screen]
S --> U
A typical pattern is to prompt the user, read their input, process it, and display the result:
# Calculate the area of a rectangle
length = float(input("Enter the length: "))
width = float(input("Enter the width: "))
area = length * width
print(f"The area is {area}")
In pseudocode:
OUTPUT "Enter the length:"
length ← REAL(USERINPUT)
OUTPUT "Enter the width:"
width ← REAL(USERINPUT)
area ← length * width
OUTPUT "The area is ", area
When processing input, you often perform calculations. The standard arithmetic operators are:
| Operator | Meaning | Pseudocode | Python | Example |
|---|---|---|---|---|
+ | Addition | + | + | 5 + 3 = 8 |
- | Subtraction | - | - | 10 - 4 = 6 |
* | Multiplication | * | * | 3 * 7 = 21 |
/ | Division (real) | / | / | 7 / 2 = 3.5 |
DIV | Integer division | DIV | // | 7 DIV 2 = 3 |
MOD | Modulus (remainder) | MOD | % | 7 MOD 2 = 1 |
^ | Exponentiation | ^ | ** | 2 ^ 3 = 8 |
These are particularly important at GCSE:
17 DIV 5 = 317 MOD 5 = 2Common uses of MOD:
number MOD 2 == 0total_minutes = 137
hours = total_minutes // 60 # 2
minutes = total_minutes % 60 # 17
print(f"{hours} hours and {minutes} minutes")
These are used in conditions and return a Boolean value:
| Operator | Meaning | Pseudocode | Python |
|---|---|---|---|
== | Equal to | = or == | == |
!= | Not equal to | ≠ or != | != |
< | Less than | < | < |
> | Greater than | > | > |
<= | Less than or equal | ≤ or <= | <= |
>= | Greater than or equal | ≥ or >= | >= |
"16" with 18 will not work as expected because one is a string.= instead of == — in Python, = is assignment while == is comparison."Score: " + 10 causes a TypeError in Python.Exam Tip: Always show the prompt message inside
input()or as a separateOUTPUTstatement. Examiners like to see clear, user-friendly prompts.
print() in Python, OUTPUT in pseudocode).input() in Python, USERINPUT in pseudocode).int() or float() as needed.DIV and MOD.MILES_TO_KM = 1.60934
miles = float(input("Distance in miles: "))
km = miles * MILES_TO_KM
print(f"{miles} miles is {km:.2f} km")
For input 10:
| Variable | Value |
|---|---|
miles | 10.0 |
km | 16.0934 |
Expected output: 10.0 miles is 16.09 km
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.