Author: admin

48. Using pickle

If you use lists to store the data from your program, there is a neat function called pickle() that can be used to save the entire list rather than using loops The example below saves a list to a file and then reloads it The data is not stored as text though, so you can’t […]

47. Writing a list into a file

A really important thing you will need to be able to do is read and write text files with variable numbers of lines Because we don’t know how many lines there will be, we tend to read text files into a list, make any changes, and then write the whole list back over the file […]

6. Test 1 – Ask and tell

Main Task Write a program that will: Prompt and ask for name and favourite colour. Returns a message like the example shown below Extension Task Extend your program so it asks for first name and surname separately, and prints the users full name, as well as their favourite colour Hints You will need to use […]

5. Input

Once you understand variables, you can take input from the keyboard and store it All input from the keyboard is stored as a string The example below asks the user to Enter something and stores the input in a variable called thing Tasks Write a program that asks for a name, and prints out the […]

4. Variables pt. 2

You can reassign variables at any point in your program You can perform arithmetic on numbers, and add string variables together Tasks Copy the code below. What is happening to the message variable? Reassign the message variable again and print it out Change the messages printed in the program Add the code above. One of […]

3. Variables Pt. 1

Variables are names we attach spaces in the computer memory where we can store numbers, characters and strings Computer memory is like a huge filing cabinet Each time we put something into the cabinet, we label it so we can find it again later I might call it x, i or total Make sure the […]

2. Output

The print() function allows you to output something to the screen Text must be enclosed in “” \n and \t are escape characters. Make sure you understand what they do Tasks Create programs to… print your name three times, separated by a space draw Robbie the robot print the number table Save and label your […]

1. Accuracy

If you can’t write code accurately, you’ll have difficulty with programming Correct spelling and accurate use of other important symbols (brackets, colons, speech marks) is crucial Case also matters. Instructions are always in lowercase (highlighted orange or purple in the code below) Double and single quotes are interchangeable most of the time. Choose one or […]

The IDLE Interpreter

A very powerful beast. Works magic with numbers. It’s kind of like a calculator on steroids. Work out what the following operations do by typing them into the IDLE interpreter shell and hitting ENTER. Try to work out what each line of code is doing. Tasks Type the commands into the IDLE interpreter, and make […]