CIS 40

Unit 2 Assignment

Practice using IDLE to create, save and debug a script file, as follows:

  1. Open IDLE's Python shell (it should say Python 3.5.2 Shell at the top).
  2. At the shell prompt, type: print("Hello world!") and then press Enter.
  3. From the shell menu, open a text editor window by selecting File > New File.
  4. In the text editor, type: print("This is line 1 of the script") at the beginning of the file.
  5. From the text editor menu, save the script in a file called by selecting File > Save. Save the file on either the H: drive or on your USB thumbdrive.
  6. 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.
  7. After line 1 of the script, type: print("This is line 2 of the script")
  8. After line 2, type: print("This is line 3 of the script")
  9. Run the module again. Note that you are prompted to save your script file again.
  10. Edit line 2 to remove the closing parentheses (this will cause an error).
  11. 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!
  12. Fix the error.
  13. After line 3, type: x = 1/0 (we will cover math and variables in the next module).
  14. 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.
  15. From the text editor menu, select Edit > Go to Line > 4 to go to line 4 where the error occurred.
  16. Fix the error by changing the line to read: x = 1/3.
  17. Run (and save) the module again and show the script and execution results to the instructor.