170 likes | 317 Views
Starter. Can you pick 3 errors from this. Temp = input("What is the temperature in the house?") if ( int (Temp) <= 15): Print ("The temperature is ", Temp, "degrees. Time to put the heating on") else: print "The temperature is ", Temp, "degrees. The heating is going off".
E N D
Starter Can you pick 3 errors from this Temp = input("What is the temperature in the house?") if (int(Temp) <= 15): Print ("The temperature is ", Temp, "degrees. Time to put the heating on") else: print "The temperature is ", Temp, "degrees. The heating is going off"
Starter Can you pick 3 errors from this Temp = input("What is the temperature in the house?") if (int(Temp) <= 15): Print ("The temperature is ", Temp, "degrees. Time to put the heating on") else: print ("The temperature is ", Temp, "degrees. The heating is going off“) How tedious is that?
Lesson Outcomes • 2.1.3 Be able to identify differentiate between types of error in programs • 2.1.4 Be able to interpret error messages and identify, locate and fix errors in a program. • 2.1.7 Be able to make effective use of tools offered in an integrated development environment [watcher, break points, single step, step throughs] • What causes error messages • All of should be able to recall different error types • All of you should be able to recall error messages in python
Making errors... • Making mistakes is okay. It happens all the time! • But you don’t release a game with errors • http://www.bbc.co.uk/news/technology-25137093 • http://www.youtube.com/watch?v=9zjGgau3iF8&safe=active
Errors in programs and being able to handle them. There are basically 3 types Of error… • Logic • Syntax • Runtime
Errors in programs and being able to handle them. • An error in the design of the program, wrong programming or wrong logic. (May not produce an error – just wrong outcome) often no obvious error is flagged up • Often due to mistake in the algorithm or wrong data type. • Format errors failing to follow the grammar rules of the programming language used.
What errors? print hello world
What errors? Name = 'Al' print(‘You can call me ' + name)
What errors? spam = 'THIS IS IN LOWERCASE.' spam = spam.lowerr()
What errors? x = 3 y = 4 average = x + y / 2 print(average)
What errors? spam = ['cat', 'dog', 'mouse'] print(spam[6])
Errors in programs and being able to handle them. Type Error Runtime NameError ZeroDivisionError KeyBoardInterrupt • When a name is used that is not known about (often a variable name that is misspelt). • Dividing a number by zero. • When a program is interrupted from the keyboard by pressing control+c. • An error occurs when the program is running. • When an operation is attempt that is invalid for that type of data.
Odd task alert Go away and try to make mistakes: Make an example of: A runtime error A syntax error A logic error
Trace Table • A technique used to test algorithms to see if any logic errors occur when the algorithm is processed.
Testing for errors during the execution of code • Breakpoints • Steps • Watches
Activity 4.1 and 4.2 • 4.3 • 4.4 • 4.5 and 4.6