Presentation is loading. Please wait.

Presentation is loading. Please wait.

Data Validation while loops. Data validation Programs get input data from different sources All data should be ‘validated’ before the program tries to.

Similar presentations


Presentation on theme: "Data Validation while loops. Data validation Programs get input data from different sources All data should be ‘validated’ before the program tries to."— Presentation transcript:

1 Data Validation while loops

2 Data validation Programs get input data from different sources All data should be ‘validated’ before the program tries to process it Depends on the specifications – what is valid data in your problem? May be general “numbers greater than zero” May be specific “only Y or N allowed”

3 What to do when invalid? What does your code do when invalid data is seen? Depends on the specification again Possible actions for invalid data stop the program (with explanatory error message, please!) give the user another chance to enter data (from the keyboard, probably) use a default value for the data and proceed as usual skip the bad data and proceed as usual (not always possible)

4 Using sentinel logic to validate keyboard input The requirement is that the user must enter Y or N or Q, nothing else Design ask the user for input while the input is NOT valid display an error message (with acceptable inputs shown) ask the user for input The trickiest part is the condition for the while while inp != ‘Y’ and inp != ‘N’ and inp != ‘Q’: is what you need. A common mistake is to use or instead of and If both cases of letters are allowed, it is simpler to change the input to one case, then test as above (remember the.upper and.lower methods)


Download ppt "Data Validation while loops. Data validation Programs get input data from different sources All data should be ‘validated’ before the program tries to."

Similar presentations


Ads by Google