GCSE Computer Science (CIE)

Topic Summaries

ALGORITHMS AND PROGRAMMING: Designing, creating, and refining algorithms

Amending algorithms

  • On the right is an example of a program to identify whether a user’s test score is above a threshold of 50%.

# Original algorithm

score = int(input(“Enter score:”))

 
 

if score < 0 or score > 100:

print(“Invalid score”)

elif score > = 50:

print(“Pass”)

else:

print(“Fail”)

  • If we needed to amend this algorithm to account for a new requirement, such as checking for scores above 90 to be awarded a distinction, then we could add the following

# Amended algorithm

score = int(input(“Enter score:”))

 
 

if score < 0 or score > 100:

print(“Invalid score”)

elif score > = 70:

print(“Distinction”)

elif score > = 50:

print(“Pass”)

else:

print(“Fail”)

Unlock Amending algorithms

Sign up to unlock the rest of this topic — plus every other topic, video, flashcard set and eBook guide in your SnapRevise Digital subscription.

Cancel anytime — instant access the moment you sign up.