CIS 40
Unit 2 Assignment
Practice using IDLE to create, save and debug a script file, as follows:
-
Python install
-
Open IDLE's Python shell (it should say Python 3.5.2 Shell at the top).
-
At the shell prompt, type: print("Hello world!") and then press Enter.
-
From the shell menu, open a text editor window by selecting File > New File.
-
In the text editor, type: print("This is line 1 of the script") at the beginning of the file.
-
From the text editor menu, save the script in a file called Lab1.py by selecting File > Save. Save the file on either the H: drive or on your USB thumbdrive.
-
From the text editor menu, select Run > Run Module (a script file is also called a module). Note that the output of the script is shown in the shell.
-
After line 1 of the script, type: print("This is line 2 of the script")
-
After line 2, type: print("This is line 3 of the script")
-
Run the module again. Note that you are prompted to save your script file again.
-
Edit line 2 to remove the closing parentheses (this will cause an error).
-
Run the module again. Note that IDLE detects a syntax error, but that it directs you to line 3 rather than line 2 - debugging isn't always straightforward!
-
Fix the error.
-
After line 3, type: x = 1/0 (we will cover math and variables in the next module).
-
Run the module again. Note that we get a runtime error, shown in the shell. The error message tells us the type of error (ZeroDivisionError), and that it occurred on line 4.
-
From the text editor menu, select Edit > Go to Line > 4 to go to line 4 where the error occurred.
-
Fix the error by changing the line to read: x = 1/3.
-
Run (and save) the module again and show the script and execution results to the instructor.