Introduction to Python — Session 8
In this session we cover:
- Files
- Reading Files
- Writing Files
Write your code
Questions
Section A
- Read the file 'jabberwocky.txt' and print its content to the screen
- Read the file 'austen.txt' and print the amount of lines in the file
- Each line of the file 'numbers.txt' contains a number, write a script to add up all the values in the file
Section B
- Ask the user to enter their name and append this to a file called 'register.txt'
- Create a new file called 'even.txt' that contains only the even numbers from the file 'numbers.txt'
- 'secret.txt' contains a secret message. Each number represents the letter of the alphabet where 1 = A, 2 = B ... Z = 26. Work out what the secret message says
- Benford’s law states that the leading digits in a collection of data are probably going to be small. For example, most numbers in a set (about 30%) will have a leading digit of 1, when the expected probability is 11.1% (i.e. one out of nine digits). Fake data is usually evenly distributed, where as real data The files 'accounts_1.txt', 'accounts_2.txt' and 'accounts_3.txt' contain financial transaction data. Work out which of the files contains fake data.