File Handling


In the first week, you were introduced to state. In the second week, you were introduced to iteration, one of the more difficult programming constructs to grasp. Last week, we discussed another programming construct: selection. In this week's lab, we will reinforce everything we have learnt so far while incorporating this weeks topic: file handling.

Your task this week is to create your own version of the game 'Hangman' in Python.

If you can develop a dynamic, adjustable solution on your own, attempt this now. You should use the EnglishWords.txt (Click here to download!) file as a bank of words to read from for randomised word selection.

If you would like some more assistance, work through the tasks in this lab. By the end, you will have built a fully functional Hangman game!

image

Open Code Editor






Click here to go to the COMP16321 Blackboard page


Click anywhere to close this video

Contents



Introduction

Task 1 - Problem Solving and Trace Tables

Task 2 - Creating a Simple Program

Task 3 - Adding Complexity

Task 4 - A bit more Complexity (finally, files)

Task 5 - Adding a Difficulty Level

Extension Exercises

Conclusion


Green = Current Page

Click anywhere to close this overlay

Topics Covered in this Lab



1. Interpreting algorithmic designs

2. Tracing through an algorithmic design

3. Variable declaration and initialisation or assignment

4. Iteration (while and for)

5. Obtaining user input

6. String and Character equality checks

7. Selection (if and else)

8. Outputting information and variable values

9. Python lists and the array operator

10. The random library and the choice method

11. The len() function to obtain the length of a string

12. Using return values as conditional state- ments

13. Opening and reading from files

14. Cleaning file contents

15. Appending values to an existing list



Click anywhere to close this overlay

Lab Key



Notes – #FF6F61

Videos – #34568B

Code Examples – #009B77

Downloads - #C3447A

Internal Link (University Resources) – #955251

External Link (Non-University Resources)– #EFC050

Other - #660099



Click anywhere to close this overlay