Time left25:00 Answered 0 of 17 25 marks
MskProd Year 7 unit exam 25 minutes 25 marks Unit exam

Introduction to Python: Unit Exam B

Instructions

Time allowed
25 minutes
Total marks
25
Calculator
No calculator is permitted.
  • Answer all the questions.

Questions

25 marks
1What does print() do?1 mark

Tick one box.

Mark scheme0 / 1
  • LD Shows output on the screen
Model answer

print() displays output.

Marked exactly against the mark scheme. Change it only if an examiner would accept your answer.

Think this answer or mark scheme is wrong? Report it

2What does this program print?1 mark
Python code
a = 4
b = 6
print(a * b)

Mark scheme0 / 1
  • L24
Model answer

4 x 6 = 24.

Marked exactly against the mark scheme. Change it only if an examiner would accept your answer.

Think this answer or mark scheme is wrong? Report it

3What does this program print?1 mark
Python code
first = "Sam"
print("Hi " + first + "!")

Mark scheme0 / 1
  • LHi Sam!
Model answer

The strings are joined: Hi, then Sam, then !, giving Hi Sam!

Marked exactly against the mark scheme. Change it only if an examiner would accept your answer.

Think this answer or mark scheme is wrong? Report it

4What does this line print?1 mark
Python code
print((2 + 3) * 4)

Mark scheme0 / 1
  • L20
Model answer

Brackets first: 2 + 3 = 5, then 5 x 4 = 20.

Marked exactly against the mark scheme. Change it only if an examiner would accept your answer.

Think this answer or mark scheme is wrong? Report it

5Tick one box in each row to show the function you would use.3 marks
int()float()str()
Turn "12" into a whole number
Turn 7 into "7" so it can be joined to some text
Turn "2.5" into a decimal number

Tick one box in each row.

Mark scheme0 / 3
  • LTurn "12" into a whole number: int()
  • LTurn 7 into "7" so it can be joined to some text: str()
  • LTurn "2.5" into a decimal number: float()
Model answer

int() gives a whole number, float() a decimal number and str() a string.

Marked exactly against the mark scheme. Change it only if an examiner would accept your answer.

Think this answer or mark scheme is wrong? Report it

6Which line causes an error when it runs?1 mark

Tick one box.

Mark scheme0 / 1
  • LA print("Score: " + 5)
Model answer

A string and a number cannot be joined with +. The number has to be turned into a string first with str().

Marked exactly against the mark scheme. Change it only if an examiner would accept your answer.

Think this answer or mark scheme is wrong? Report it

7Complete the table to show what the program prints for each input.3 marks
Python code
score = int(input("Score: "))
if score >= 50:
    print("Pass")
else:
    print("Try again")
InputOutput
75
50
49

Mark scheme0 / 3
  • LPass
  • LPass
  • LTry again
Model answer

>= means greater than or equal to, so 50 passes and 49 does not.

Marked exactly against the mark scheme. Change it only if an examiner would accept your answer.

Think this answer or mark scheme is wrong? Report it

8age is 13. Which comparison is true?1 mark

Tick one box.

Mark scheme0 / 1
  • LC age >= 13
Model answer

13 is greater than or equal to 13.

Marked exactly against the mark scheme. Change it only if an examiner would accept your answer.

Think this answer or mark scheme is wrong? Report it

9What is a syntax error?1 mark

Tick one box.

Mark scheme0 / 1
  • LB A mistake in the rules of the language, so the program cannot run
Model answer

A syntax error breaks the rules of Python, such as a missing bracket, so the program will not run at all.

Marked exactly against the mark scheme. Change it only if an examiner would accept your answer.

Think this answer or mark scheme is wrong? Report it

10This program should print the total of two numbers, but it prints 57 when the user types 5 and then 7. Which function should be used on each input to fix it?1 mark
Python code
a = input("First number: ")
b = input("Second number: ")
print(a + b)

Mark scheme0 / 1
  • Lint
Model answer

input() gives strings, and + joins strings, so 5 and 7 make 57. int() turns each into a number so + adds them.

Marked exactly against the mark scheme. Change it only if an examiner would accept your answer.

Think this answer or mark scheme is wrong? Report it

11Write a program that asks for two whole numbers and prints their total.3 marks
answer.py

Mark scheme0 / 3
  • LAsks for two inputs
  • LConverts the inputs to integers with int()
  • LPrints the correct total, for example 12 for 5 and 7
A program that scores full marks

Convert each input with int() before adding, otherwise + joins the two strings.

Python
a = int(input("First number: "))
b = int(input("Second number: "))
print(a + b)
Marked exactly against the mark scheme. Change it only if an examiner would accept your answer.

Think this answer or mark scheme is wrong? Report it

12Which of these is a float?1 mark

Tick one box.

Mark scheme0 / 1
  • LA 7.0
Model answer

7.0 has a decimal point, so it is a float.

Marked exactly against the mark scheme. Change it only if an examiner would accept your answer.

Think this answer or mark scheme is wrong? Report it

13Explain why indentation matters in Python. Use an if statement in your answer.2 marks
Explain

Mark scheme0 / 2
  • LIndentation shows which lines belong to the if (the block)
  • LIndented lines only run when the condition is true, so wrong indentation gives an error or the wrong result
Model answer

Python uses indentation to show which lines belong to the if. The indented lines only run when the condition is true, so moving a line in or out changes what the program does, or causes an IndentationError.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.

Think this answer or mark scheme is wrong? Report it

14Complete the table to show what the program prints for each input.2 marks
Python code
mark = int(input())
if mark >= 70:
    print("A")
elif mark >= 50:
    print("B")
else:
    print("C")
InputOutput
85
70
69
12

Mark scheme0 / 2
  • L85 and 70: A, A
  • L69 and 12: B, C
Model answer

70 or more prints A, so both 85 and 70 print A. 69 is at least 50, so B. 12 is C.

Marked exactly against the mark scheme. Change it only if an examiner would accept your answer.

Think this answer or mark scheme is wrong? Report it

15What does this program print?1 mark
Python code
x = "3"
y = 4
print(int(x) * y)

Mark scheme0 / 1
  • L12
Model answer

int("3") is 3, and 3 x 4 = 12.

Marked exactly against the mark scheme. Change it only if an examiner would accept your answer.

Think this answer or mark scheme is wrong? Report it

16Which of these can be used as a variable name in Python?1 mark

Tick one box.

Mark scheme0 / 1
  • LB high_score
Model answer

A name cannot start with a digit, cannot contain a space and cannot be a keyword such as class.

Marked exactly against the mark scheme. Change it only if an examiner would accept your answer.

Think this answer or mark scheme is wrong? Report it

17What does this line print?1 mark
Python code
print("Total: " + str(3 + 4))

Mark scheme0 / 1
  • LTotal: 7
Model answer

3 + 4 is 7, str() turns it into "7", and it is joined to "Total: ".

Marked exactly against the mark scheme. Change it only if an examiner would accept your answer.

Think this answer or mark scheme is wrong? Report it

Machine mark 0 / 25