All topics › OCR GCSE Computer Science › Variables, constants, input, output and assignment
Variables, constants, input, output and assignment
OCR GCSE Computer Science (J277) · Algorithms and programming (Paper 2) › Programming fundamentals › Programming fundamentals
Practise Variables, constants, input, output and assignment. 12 exam-style questions plus unlimited generated ones on this subtopic, at up to four difficulty levels, with full mark schemes and a progress tracker. Free, no account needed.
Build a paper on this topic
▶ Watch videos on Variables, constants, input, output and assignment (Craig 'n' Dave OCR on YouTube) · Practise all of Programming fundamentals
Quick recall Cover the answers and test yourself. The app has these as flashcards that come back just before you'd forget them.
Look at this program.01 const VAT = 0.2
02 price = float(input("Enter price"))
03 total = price + price * VAT
04 print(total) Identify the constant used in the program.VAT Look at this program.01 name = input("What is your name?")
02 age = int(input("How old are you?"))
03 age = age + 1
04 print("Next year " + name + " will be " + str(age)) State the output if the user enters Sam and then 14.Next year Sam will be 15 Look at this program.01 name = input("Enter your name")
02 const GREETING = "Welcome"
03 print(GREETING + ", " + name) Identify the constant used in the program.GREETING Sample questions Written for this site in the style of OCR exam questions. They are not taken from real past papers.
Question 1 Easy 4 marks
Look at this program.
01 const VAT = 0.2
02 price = float(input("Enter price"))
03 total = price + price * VAT
04 print(total)(a) State what is meant by a variable .[1]
(b) State what is meant by a constant .[1]
(c) Identify the constant used in the program.[1]
(d) Identify the line number of the line that outputs data.[1]
Show the answer and mark scheme (a) a named location in memory that stores a value that can change while the program is running (b) a named value that cannot change while the program is running Question 2 Medium 5 marks
A gym uses this program to work out the cost of a membership.
01 const MONTHLY_FEE = 25
02 months = int(input("Number of months"))
03 cost = MONTHLY_FEE * months
04 if months >= 12 then
05 cost = cost - 30
06 endif
07 print(cost)(a) State the output when the user enters 12.[1]
(b) Explain why MONTHLY_FEE has been declared as a constant rather than as a variable.[2]
(c) Identify one other value in the program that could be declared as a constant.[1]
(d) A programmer adds the line MONTHLY_FEE = 30 near the end of the program. Explain what would happen.[1]
Show the answer and mark scheme (b) its value does not need to change while the program runs / it cannot be changed by mistake if the fee changes, it only needs to be updated in one place, making the program easier to maintain (c) 30 (the discount) / 12 (the number of months needed for the discount) (d) an error would be reported / the program would not run, because the value of a constant cannot be changed Question 3 Hard 7 marks
This program should work out the interest earned on a savings account. It contains two errors.
01 const RATE = 0.05
02 balance = float(input("Enter balance"))
03 years = int(input("Enter years"))
04 for y = 1 to years
05 interest = balance * RATE
06 balance = balance + interest
07 next y
08 RATE = 0.06
09 print("Final balance: " + str(balance))
10 print("Total interest: " + str(totalInterest))(a) Identify the two errors in the program and explain why each one is an error.[4]
(b) Describe the changes needed so that line 10 outputs the total interest earned.[2]
(c) The errors are corrected. State the output of line 09 when the user enters 1000 and 2.[1]
Show the answer and mark scheme (a) line 08 the value of a constant cannot be changed while the program is running line 10 totalInterest is used but has never been declared / given a value (b) set totalInterest to 0 before the loop inside the loop, add interest to totalInterest (totalInterest = totalInterest + interest) (c) Answer: Final balance: 1102.5
Related subtopics
Stuck? Get 1-to-1 help. Chhetri Academy tutors GCSE and A level Maths and Science online, with a free 30-minute trial lesson.
Book a free trial