1Medium
0/10

A programmer has started to write a program, but it does not work correctly. The program should ask the user, "Do you want to begin the countdown?". The user then responds 'y' or 'n'. If the user types 'y', then the computer displays a countdown from 5 down to 1, followed by "Takeoff!".

Below is the buggy source code:

a = input()

if a == "y"
    for timer in range(5, 0 -1):
        print(timer)
    print("Takeoff!"

Amend the code to:

  • fix the syntax error on line 3
  • fix the syntax error on line 4
  • fix the syntax error on line 6
  • change the identifier a to a more meaningful name
  • display a suitable prompt question for the user
  • accept the user's input of 'y' or 'n' (no validation is required)
  • add a comment to explain the effect of the range function's last parameter, set to -1
  • add two uses of blank space (white space) to aid readability.

Do not add any additional functionality.

[10]

Develop code Questions

Practise Edexcel GCSE Computer Science Develop code with exam-style questions for GCSE Computer Science. 57 questions covering Decomposition and abstraction to solve problems, Read, write, analyse and refine programs, Converting algorithms into programs, Techniques for readable, maintainable code, Identifying and correcting program errors, and Evaluating program fitness and efficiency, matched to the Edexcel GCSE Computer Science (1CP2) specification and written in Paper 1 and Paper 2 style. Every question includes a full worked solution and mark scheme, so you can see where marks are awarded rather than just whether you got the answer right.

Next

Develop code Questions

  1. GCSE
  2. /Computer Science
  3. /Develop code