To write a Python program, you first need to open Pyscripter To write a Python program, you first need to open Pyscripter. Go to the shared area\ICT\Portable Python and double click on Pyscripter-Portable.exe
You will see a screen like the one below You will see a screen like the one below. Remove the code in the main window and then you’re ready to go!
Now press the run button: Your first program: Hello world Type the below code into the main window: print(“Hello World”) Now press the run button: You should see the output: Now try to get it to output ‘Hello (Your Name)’
Next we’re ready to use variables: someText = input(“What is your name?”) print(“Welcome ” + someText) Now see if you can get the computer to also ask what your favourite colour is and what your favourite animal is. Then it should output a sentence like: Your teacher will show you this video to help understand variables (until 1min 30s): http://www.youtube.com/watch?v=aeoGGabJhAQ
Time to do some calculations, try each of these: print(137+172) print(200-132) print(1234*67) print(12000/4)
Now try this: someNumber = 345 anotherNumber = 457 Print(someNumber + anotherNumber) Now try dividing, multiplying and subtracting someNumber and anotherNumber
We can now try making a calculator by asking for two numbers and storing them in variables: num1 = input(“Enter the first number”) num2 = input(“Enter the second number”) However, the computer will assume these numbers are text, so now we have to convert them to numbers (integers): num1 = int(num1) num2 = int(num2)
Now try to get the computer to print the answer to num1 multiplied by num 2 And try to get the computer to print the answer to num1 added to num 2
You can make it a bit more user friendly by putting some additional text in: print(“The answer to “ , num1 , “ multiplied by “ , num2 , “ is: “ , num1*num2)
Now it’s time to make a miles to kilometres converter program Can you make a program that: - Asks how many miles you would like to convert - Stores the answer in a variable - Converts the contents of that variable into a number - Multiplies the number of miles by the number of kilometres in a miles (you can find this information out on the web) - Prints out the answer saying something like “The number of kilometres in 6 miles is 9.65 kilometres”