Introduction to Python: Unit Exam A
Output, variables and data types, input and casting, arithmetic, and if, elif and else, including writing a short program.
Instructions
- Time allowed
- 25 minutes
- Total marks
- 25
- Calculator
- No calculator is permitted.
- Answer all the questions.
- The number of marks for each question is shown in brackets. Use it as a guide to how much to write.
- The clock at the top counts down from the real time allowed. When it reaches zero the paper is locked and marked, as it would be collected in the exam hall.
- Read every question to the end before answering. Where a question says tick two boxes, tick exactly two: ticking more than asked scores nothing. Type one word and number answers carefully, because they are marked exactly.
Questions
Answer every question, then finish the paper to have it marked. Marking as you go teaches you far less.
Tick one box.
- LA print("Hello")
Python is case sensitive: it must be print in small letters, with the text in brackets and quotation marks.
age = 12
age = age + 1
print(age)- L13
age starts at 12 and is replaced by 12 + 1, so 13 is printed.
| Integer | Float | String | |
|---|---|---|---|
| 42 | |||
| 3.5 | |||
| "42" | |||
| "Hello" |
Tick one box in each row.
- L42: Integer
- L3.5: Float
- L"42": String
- L"Hello": String
Whole numbers are integers, numbers with a decimal point are floats, and anything in quotation marks is a string, even "42".
- Lstring
input() always returns a string, even if the user types digits.
Tick one box.
- LD Because input() gives a string, and a number cannot be added to a string
input() returns text. int() turns it into a whole number so that arithmetic works.
print(7 + 3 * 2)- L13
Multiplication happens before addition: 3 x 2 = 6, then 7 + 6 = 13.
print("7" + "3")- L73
Both are strings, so + joins them: "7" and "3" make 73.
temp = int(input("Temperature: "))
if temp > 25:
print("Hot")
elif temp > 15:
print("Warm")
else:
print("Cold")| Input | Output |
|---|---|
| 30 | |
| 25 | |
| 15 | |
| 20 |
- LHot
- LWarm
- LCold
- LWarm
30 is over 25, so Hot. 25 is not over 25 but is over 15, so Warm. 15 is not over 15, so Cold. 20 is Warm.
Tick one box.
- LB ==
= stores a value in a variable. == compares two values.
Tick one box.
- LC The closing quotation mark is missing
Every string must be closed with a matching quotation mark, so this is a syntax error.
Tick one box.
- LA To show which lines belong to the if, so they only run when the condition is true
Indentation shows Python which lines are inside the if.
# Write your program below
- LUses input() to ask for the name
- LPrints Hello and the name that was typed in
- LWorks for any name, because the name is stored in a variable and used in the output
Store what input() returns in a variable, then join it to Hello in the print.
name = input("What is your name? ")
print("Hello " + name)x = 10
x = x - 4
x = x * 2
print(x)- L12
x is 10, then 6, then 12.
- LA variable is a named location in memory that stores a value
- LThe value can change while the program runs, and it can be used again later in the program
A variable is a named place in memory that holds a value. Programs use variables so a value can be remembered, used again later and changed while the program runs, such as a score going up.
Tick one box.
- LC lives = 5
The variable name goes on the left of =, and the value on the right.
print(10 / 4)- L2.5
/ is ordinary division and always gives a float: 10 / 4 = 2.5.
This is an original Key Stage 3 assessment. Most questions are closed, so the marking is exact, and the written answers are marked against a mark scheme in the same style as a GCSE paper, so the format is familiar long before it counts.