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
- Declare Integer Number
- Get Number from user
- While Number < 0 OR Number > 100
- Display “Sorry that number is not valid”
- Get number from user
- End While
- 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.