Numbers can be integer (no decimal point) or float (decimal point) The example below declares two variables, one of each type and prints them as integers, floating point numbers and as strings if no type is specified, the variable will print as it was input Tasks Type in the code and test that it works […]
Category: Uncategorized
Variables contain either string, integer or float data All user input is stored as a string by default, meaning an extra step is required to convert the input to the correct data type For example, the program below will not output the expected result (doubling the age entered) This is because you shouldn’t add a […]
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 […]
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 […]
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 […]
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 […]
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 […]
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 […]
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 […]
The first thing to do once Python is installed it to create your very first program. Try that here.