CIS 40

Unit 2 Assignment

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

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