Validations and Error Handling

Slides:



Advertisements
Similar presentations
CS107 Introduction to Computer Science Lecture 3, 4 An Introduction to Algorithms: Loops.
Advertisements

Variables –recap-python
Python November 18, Unit 7. So Far We can get user input We can create variables We can convert values from one type to another using functions We can.
1 Lab Session-7 CSIT-121 Fall Introducing Structured Choice 4 The do~While Loop 4 Lab Exercises.
An Introduction to Textual Programming
General Programming Introduction to Computing Science and Programming I.
08/10/ Iteration Loops For … To … Next. 208/10/2015 Learning Objectives Define a program loop. State when a loop will end. State when the For.
Dealing with Errors. Error Types Syntax Errors Runtime Errors Logical Errors.
Address book By NIRMIT GANG. Main Program  Selection Screen 1.Enter Data 2. Read Data 3. Search Data 4. Modify Data 5. Delete Data 6. Exit Choice.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Writing JavaScript Functions. Goals By the end of this unit, you should understand … How to breakdown applications into individual, re-usable modules.
1. Understand how to catch errors in a program 2. Know how to filter user input to stop incorrect data.
ECS 15 Variables. Outline  Using IDLE  Building blocks of programs: Text Numbers Variables!  Writing a program  Running the program.
End of unit assessment Challenge 1 & 2. Course summary So far in this course you have learnt about and used: Syntax Output to screen (PRINT) Variables.
Verification & Validation. Batch processing In a batch processing system, documents such as sales orders are collected into batches of typically 50 documents.
Exceptions Chapter 16 This chapter explains: What as exception is Why they are useful Java exception facilities.
Designing While Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Data Validation while loops. Data validation Programs get input data from different sources All data should be ‘validated’ before the program tries to.
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
Creating a mystic meg program A simple program asking the user questions and using their answers to build up a fortune telling in a list.
REVIEW No curveballs this time …. PROBLEM TYPE #1: EVALUATIONS.
© The McGraw-Hill Companies, 2006 Chapter 3 Iteration.
Intro to Loops 1.General Knowledge 2.Two Types of Loops 3.The WHILE loop 1.
 CSC111 Quick Revision. Problem Write a java code that read a string, then show a list of options to the user to select from them, where:  L to print.
Exception Handling and String Manipulation. Exceptions An exception is an error that causes a program to halt while it’s running In other words, it something.
GCSE Computing: Programming GCSE Programming Remembering Python.
While loops. Iteration We’ve seen many places where repetition is necessary in a problem. We’ve been using the for loop for that purpose For loops are.
Visual Basic Declaring Variables Dim x as Integer = 0 In the statement above, x is being declared as an Integer (whole number) and is initialised.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Marr CollegeHigher Software DevelopmentSlide 1 Higher Computing Software Development Topic 4: Standard Algorithms.
Introduction to Computing Science and Programming I
Data Types Variables are used in programs to store items of data e.g a name, a high score, an exam mark. The data stored in a variable is entered from.
Lesson 4 - Challenges.
Chapter Topics 11.1 Introduction to Menu-Driven Programs
Lesson 3 - Repetition.
Iterations Programming Condition Controlled Loops (WHILE Loop)
While Loops (Iteration 2)
While loops The while loop executes the statement over and over as long as the boolean expression is true. The expression is evaluated first, so the statement.
I/O in C Lecture 6 Winter Quarter Engineering H192 Winter 2005
File Handling Programming Guides.
Topics Introduction to File Input and Output
Introduction to pseudocode
Exception Handling.
For -G7 programing language Teacher / Shamsa Hassan Alhassouni.
Multiple Selections (ELIF Statements)
Iteration: Beyond the Basic PERFORM
Coding Concepts (Basics)
Introduction to TouchDevelop
Module 4 Loops.
Lec 4: while loop and do-while loop
Do … Loop Until (condition is true)
Class Examples.
Inputs and Variables Programming Guides.
Python programming exercise
Looping III (do … while statement)
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
CHAPTER 4 Iterative Structure.
CHAPTER 6: Control Flow Tools (for and while loops)
CPS125 Week
Python Basics with Jupyter Notebook
Clear and Unclear Windows
Chapter 4: Repetition Structures: Looping
Data Types and Maths Programming Guides.
CSE 231 Lab 2.
Topics Introduction to File Input and Output
Learning Intention I will learn about the standard algorithm for input validation.
IST256 : Applications Programming for Information Systems
Lecture 1 Review of 1301/1321 CSE /26/2018.
Challenge Guide Grade Code Type Slides
Flow Control I Branching and Looping.
Presentation transcript:

Validations and Error Handling Programming Guides

Validations and Error Handling Validation When users enter data, validations ensure that the data entered is the expected data. For example: If a program is asking for a menu choice (1, 2, 3) the program can validate that only numbers 1-3 are entered – it will reject other numbers. If a program is collecting last names to be entered in a database, the program validates that only letters are entered and not numbers. In a survey collecting data in the form of "yes" or "no" questions, the program validates that only Yes or No is entered and not some other word.

Validations and Error Handling ‘While Loops’ to Validate Data Entry An input statement to record the user’s answer to the question answer = input(“Do you wish to carry on? Type YES or NO") while (answer != "YES") and (answer != "NO"): answer = input("Wrong word entered, please type YES or NO") if answer == "YES": print("You want to carry on!") else: print("You don't want to carry on!") input() Do you wish to carry on? Type YES or NO yessss A while loop to keep asking for input until the user enters YES or NO. Wrong word entered, please type YES or NO yes Wrong word entered, please type YES or NO YES You want to carry on! If-Else statements to act on the users input

Validations and Error Handling ‘While Loops’ to Validate Data Entry menuchoice = 0 print('*****Menu*****') print('') print('1. Display my name') print('2. Display my age') print('3. Display my address') while (menuchoice < 1) or (menuchoice > 3): menuchoice = int(input("What is your menu option?")) if menuchoice == 1: print("Mr Wickins") elif menuchoice == 2: print("29 years old") elif menuchoice == 3: print("Sidmouth") print("Goodbye") A variable created which is set to zero A simple text based menu printed to the screen -1 What is your menu choice? 4 What is your menu choice? A while loop to keep asking for input until the user enters 1, 2 or 3. 2 29 years old Goodbye If-Else statements to ‘act’ on their input.

Validations and Error Handling Often when our programs ask for an input, because it automatically stores the input as a string, it doesn’t matter what data type is entered. However, consider a program that asks the user to type in a number and immediately converts it to an integer data type. If the user types in anything other than an integer, the program will crash and close! This is not good as we want our programs to be unbreakable. To overcome this issue, we need to be able to handle any errors that our programs face.

Validations and Error Handling This is an example of exception handling (error handling). The program enters an infinite loop and then tries the input statement. If the user enters a value which can be converted to an integer, the loop will break and the program will carry on… …however, if the user types in a non integer data type, an error will occur. But instead of the program crashing, the error is handled and a print statement is outputted. The loop then repeats and the user is asked to type in a number again.