N5 – Input Validation

Today we looked at the following problem

Write a program which will allow a user to input only a number in the range 0-100. An error message will be output if the number is invalid.

The program will output a message when the number input is valid (after the loop for checking the number).

We then worked through Analysis, Design, Implementation and Testing of the program.

Analysis

Input – a number

Process – check number is between 0 and 100

Output – a message about the numbers validity

Design

We looked at all three design methodologies and created designs in our jotter.

Pseudocode

  1. Declare Integer Number
  2. Get Number from user
  3. While Number < 0 OR Number > 100
  4.     Display “Sorry that number is not valid”
  5.     Get number from user
  6. End While
  7. Display “That is a valid number”

Flowchart

Structure Diagram

Implementation in Python


number=0 # declare number as type integer
number = int(input("Please enter a number from 0 - 100 "))
while number < 0 or number > 100:
    print("Sorry that number is not valid")
    number = int(input("Please enter a number from 0 - 100 "))
print("That is a valid number")

Testing

We tested the code with Normal, Extreme and Exceptional test data.

Leave a Reply

Your email address will not be published. Required fields are marked *