Sunday 10 August 2014

5. Development of Code

Q

As you begin to develop more complex programs you will experience error messages.  The great thing about Python is that it tends to explain the error you have made in detail.  Your job is to understand what these mean and to put them right.

LEARNING OBJECTIVES

You will learn to:
Interpret common error messages
Understand how to debug a program
Understand and use comment statements
Understand the file/new window
Save a program in scripting mode


TASK 1

Copy and run this code and explain the result.

>>>print hello world


TASK 2

Copy and run this code and explain the result.

>>>print("hello world")

TASK 3

Python produces different types of error.  In your learning blog match the type of error with the description of error.


Type of error

TypeError

RuntimeError

NameError

ZeroDivisionError

KeyBoardInterrupt

 

Description of the error

Dividing a number by zero.

When a program is interrupted from the keyboard by pressing control+c.

When a name is used that is not known about (often a variable name that is misspelt).

When an operation is attempt that is invalid for that type of data.

An error occurs when the program is running.


TASK 4

 

Experiment with Python to see if you can create each type of error.

Hint: A full list of Python errors can be found here:http://www.tutorialspoint.com/python/standard_exceptions.htm

TASK 5


Copy and run this code and explain the result.

# Programmer Amy Smith 6th September 2013


TASK 6


Use file/new window to open a script file in the IDLE.
Copy this code into the file.

print("So long and thanks for all the fish")

print("The answer is",6*7)

 

Save the file using file/save. Always give the filename an extension of .py. Use a meaningful filename and store in a suitable folder.
Run the commands by using run/run module

HOMEWORK

Using the Python IDLE

Write your own summary sheet to describe how to run Python programs, including how to save and open .py files. Include any other commands that you have found useful.  

Using the Python IDLE

 

How to open a new window

 

How to save a file

 

How to open a file

 

How to run a program

 

 

 

 

 

 

 

Useful tips

 

alt p

Displays the last line you entered

Commands in the file are not colour coded

Save as a .py file

 

 

 

 



No comments:

Post a Comment