- Describe the purpose of input and output in a program
- Use SQA reference language for receiving input and sending output
- Set up a simple Python project in PyCharm and run a program
- Use Python
input(),print(), casting, and+concatenation - Apply common string operations including length, concatenation, substring, and case conversion
- I can write
RECEIVEandSENDstatements in SQA reference language - I can explain why keyboard input often needs converted before arithmetic
- I can create, save, run, and fix a simple Python file in PyCharm
- I can combine text and variables in output without causing a type error
- I can trace and write code that uses common string operations
Answer before the lesson begins. These check prior knowledge from variables, data types and arithmetic.
1. Which data type is most appropriate for the value "Edinburgh"?
2. What is the result of "High" & "School" in SQA reference language?
3. Which expression correctly calculates the average of three variables?
Key vocabulary
+ operator at N5name.upper()Input, Output and String Operations
Programs need a conversation with the user
A program is useful when it can accept data, process it, and show a result. Input is data entering the program. At National 5 this usually means data typed using the keyboard. Output is information leaving the program. This is usually text displayed on the screen.
In SQA reference language, input and output have a very specific style. Output uses SEND ... TO DISPLAY. Input uses RECEIVE ... FROM (TYPE) KEYBOARD. The type in brackets matters because it tells the reader what kind of data is expected.
SEND "Enter your age: " TO DISPLAY RECEIVE age FROM (INTEGER) KEYBOARD SEND "You are " & age & " years old." TO DISPLAY
Python input and output
Python uses print() for output and input() for keyboard input. The message inside input() is called a prompt. It should be clear enough that the user knows exactly what to type.
name = input("Enter your name: ")
print("Hello " + name)
There is one crucial Python detail: input() always returns a string. Even if the user types 14, Python stores "14" unless you convert it. To do arithmetic, cast the input using int() for whole numbers or float() for decimal numbers.
age = int(input("Enter your age: "))
height = float(input("Enter your height in metres: "))
Using PyCharm for implementation
PyCharm is an Integrated Development Environment, or IDE. It gives you an editor, a run button, error highlighting, and a console in one place. For this course, use one project folder for SDD practice and create one Python file per lesson or task. A sensible file name for this lesson is sdd6_strings.py.
When you create a new PyCharm project, choose a plain Python project, keep the location somewhere you can find again, and make sure a Python interpreter is selected. Then create a new Python file, type your program, and run it using the green Run button or by right-clicking the file and choosing Run. The program output appears in the Run panel at the bottom.
Professional programmers run tiny tests often. Type a few lines, run them, check the output, then continue. This makes mistakes easier to find than writing a whole program before running it for the first time.
Combining text and variables
Output often needs to combine fixed text with variable values. SQA reference language uses & for concatenation, while Python uses +. In Python, numbers must be converted with str() before they can be joined to text using +:
name = "Sam" score = 12 print(name + " scored " + str(score) + " points")
For this course, use + when practising concatenation, and convert non-string values with str() first.
String operations
A string is a sequence of characters. Python can measure, transform, and slice strings. len(name) returns the length. name.upper() changes letters to uppercase. name.lower() changes letters to lowercase.
greeting = "hello" print(greeting.upper()) # HELLO print(len(greeting)) # 5
Python also lets you access characters by position. The first character is index 0, the second is index 1, and so on. A substring can be taken using slicing, for example code[0:3] gives characters from index 0 up to, but not including, index 3.
code = "N5CS2026" print(code[0]) # N print(code[0:4]) # N5CS print(code[2:6]) # CS20
Exam wording versus Python code
Exam questions are expressed in SQA reference language, so you must be able to read it. When writing code answers, you may use any programming language; marks reward correct understanding and logic rather than exact syntax. RECEIVE age FROM (INTEGER) KEYBOARD and age = int(input("Enter age: ")) represent the same input operation in SQA notation and Python.
Worked examples
A program asks for a first name and displays a greeting.
DECLARE firstName AS STRING INITIALLY "" SEND "Enter your first name: " TO DISPLAY RECEIVE firstName FROM (STRING) KEYBOARD SEND "Hello " & firstName & "!" TO DISPLAY
SEND joins fixed text with the variable using the SQA reference-language & operator.A program asks for two marks and displays the total.
mark1 = int(input("Enter mark 1: "))
mark2 = int(input("Enter mark 2: "))
total = mark1 + mark2
print("Total mark: " + str(total))
input() returns a string, so each mark is converted using int().str(total) converts the integer total to text so it can be joined to the message using +.A program receives a username and creates a short code from the first three characters.
username = input("Enter username: ")
short_name = username[0:3].upper()
print("Your short code is " + short_name + str(len(username)))
input() receives the username as a string.username[0:3] takes the first three characters. .upper() changes them to uppercase.morgan, the output is Your short code is MOR6.A Python program asks for a city name. It should display the name in uppercase, then display the number of characters in the name.
Answer the following:
- Write the Python line that receives
cityfrom the keyboard. - Write the Python line that displays the city name in uppercase.
- Write the Python line that displays
Length:followed by the number of characters.
city = input("Enter city: ")print(city.upper())print("Length: " + str(len(city)))
input() returns a string. age = input("Age: ") stores text. Use int() or float() before arithmetic.str() when joining text and numbers in Python. "Score: " + score causes a type error if score is an integer. Use "Score: " + str(score)."Hello" + name produces HelloSam. Include a space inside the string: "Hello " + name.SEND and RECEIVE are for SQA reference language. print() and input() are for Python implementation."N5" is text[0], not text[1].Exam questions are written in SQA reference language, where output uses SEND, input uses RECEIVE, and concatenation uses &. You must be able to read this notation. When writing code answers, you may use any programming language; marks reward correct understanding and logic rather than exact syntax. In Python practical work, use print(), input(), casts, str(), and +.
Questions 1–5 are auto-checked. Questions 6–8 are self-marked — write your answer, then reveal the model answer to check your work. Questions 9–10 are practical PyCharm implementation tasks.
1. Which SQA reference language statement displays a message on the screen? TYPE 1
2. Which Python line correctly receives an integer age from the keyboard? TYPE 1
3. What does len("N5 Computing") return? TYPE 1
4. If word = "PYTHON", what is word[0:3]? TYPE 1
5. What is the output of print("Total: " + str(7 + 5))? TYPE 1
6. Write SQA reference language that asks the user to enter their town, receives it into a string variable called town, then displays You live in followed by the town. TYPE 2
DECLARE town AS STRING INITIALLY "" SEND "Enter your town: " TO DISPLAY RECEIVE town FROM (STRING) KEYBOARD SEND "You live in " & town TO DISPLAY
7. Explain why this Python code causes a problem, then write a corrected version: score = input("Score: ") then total = score + 10. TYPE 2
10 to it. Corrected version: score = int(input("Score: "))
total = score + 108. Practical: set up PyCharm for this lesson. Create or open an SDD practice project, create a new Python file called sdd6_strings.py, add the code below, run it, and record the output. TYPE 3
print("SDD6 ready")
print("Input, output and strings")
SDD6 ready Input, output and strings
9. Practical: In PyCharm, create a new Python file called sdd6_strings.py. Write a program that asks for a first name and surname, then displays a username made from the first three letters of the first name and the first three letters of the surname, all lowercase. Test with Test User and Sam Lee, and record the output from both tests. TYPE 3
first_name = input("Enter first name: ").lower()
surname = input("Enter surname: ").lower()
username = first_name[0:3] + surname[0:3]
print("Username: " + username)Expected outputs:
Test User → Username: tesuse Sam Lee → Username: samlee
10. Practical: In sdd6_strings.py, replace the previous program with one that asks for the price of an item and the quantity bought, then displays the total cost using + concatenation. Use float() for the price, int() for the quantity, and str() for the output. Test with price 2.50, quantity 4, then price 1.25, quantity 3. Record both outputs. TYPE 3
price = float(input("Enter price: "))
quantity = int(input("Enter quantity: "))
total = price * quantity
print("Total cost: £" + str(total))Expected outputs:
2.50 and 4 → Total cost: £10.0 1.25 and 3 → Total cost: £3.75
Suggested timing: 70 minutes. Warm up 5 min; notes and short live demos 20 min; PyCharm setup 15 min; worked examples 10 min; task set 20 min.
Key misconception to address: Python input() always returns a string. All pupils may think typing digits automatically creates an integer.
Live demo suggestion: Deliberately run score = input() followed by score + 10, read the type error, then fix it with int().
Extension question: Ask all pupils to improve the price task so it rejects negative quantities once selection has been taught.
SQA command words covered: identify, describe, explain, write, implement, test.