You are on page 1of 3

Refine an algorithm | Validation 1

Validation
Study the following line of code which asks the user to enter a test score in the range 0-100.

How could this code be improved in order to make it more robust?

testScore = int(input("Please enter your test score as a whole number from


0-100:"))

…………………………………………………………………………………………………………………………………………………………….

…………………………………………………………………………………………………………………………………………………………….

…………………………………………………………………………………………………………………………………………………………….

…………………………………………………………………………………………………………………………………………………………….

…………………………………………………………………………………………………………………………………………………………….

…………………………………………………………………………………………………………………………………………………………….

…………………………………………………………………………………………………………………………………………………………….

…………………………………………………………………………………………………………………………………………………………….

…………………………………………………………………………………………………………………………………………………………….

…………………………………………………………………………………………………………………………………………………………….

…………………………………………………………………………………………………………………………………………………………….

…………………………………………………………………………………………………………………………………………………………….

Page 1
Craig’n’Dave
Refine an algorithm | Validation 2

Validation
Study the following line of code which asks the user to enter a 4-digit product code which must start
with the capital letter “G” followed by any three numbers or characters.

How could this code be improved in order to make it more robust?

print = ("Product codes must start with a capital G followed by any three
numbers or letters")

code = input("Enter product code e.g. G47s :")

…………………………………………………………………………………………………………………………………………………………….

…………………………………………………………………………………………………………………………………………………………….

…………………………………………………………………………………………………………………………………………………………….

…………………………………………………………………………………………………………………………………………………………….

…………………………………………………………………………………………………………………………………………………………….

…………………………………………………………………………………………………………………………………………………………….

…………………………………………………………………………………………………………………………………………………………….

…………………………………………………………………………………………………………………………………………………………….

…………………………………………………………………………………………………………………………………………………………….

…………………………………………………………………………………………………………………………………………………………….

…………………………………………………………………………………………………………………………………………………………….

…………………………………………………………………………………………………………………………………………………………….

Page 1
Craig’n’Dave
Refine an algorithm | Validation 2

…………………………………………………………………………………………………………………………………………………………….

…………………………………………………………………………………………………………………………………………………………….

…………………………………………………………………………………………………………………………………………………………….

…………………………………………………………………………………………………………………………………………………………….

…………………………………………………………………………………………………………………………………………………………….

…………………………………………………………………………………………………………………………………………………………….

…………………………………………………………………………………………………………………………………………………………….

…………………………………………………………………………………………………………………………………………………………….

…………………………………………………………………………………………………………………………………………………………….

…………………………………………………………………………………………………………………………………………………………….

…………………………………………………………………………………………………………………………………………………………….

…………………………………………………………………………………………………………………………………………………………….

…………………………………………………………………………………………………………………………………………………………….

…………………………………………………………………………………………………………………………………………………………….

…………………………………………………………………………………………………………………………………………………………….

Page 2
Craig’n’Dave

You might also like