Theme: | Procedures, Functions and parameters |
---|---|
Subjects: | Higher Computing Science |
Audience: | Student |
When: | Wednesday, 18 November 2015 7:30 PM |
Presented by: | Ian King, SCHOLAR Online Tutor for Computing Science |
Session link: | http://heriot-watt.adobeconnect.com/scholarhomework (Enter as a Guest) |
Category: Old Higher
Higher – Categories of High Level Languages
Computing Exit Pass
- Mini Languages are langues designed for one purpose Ex HTML is used for web design
- Domain Specific languages are also know as mini languages
- Procedural languages are the most common type
- Basic is a high level language designed to be easy to learn which became the popular language when computers became cheaper and popular in the 1970s
- Procedural languages are the most common type of programming languages
- Domain oriented languages focus on one task
- A scripting language is basically a mini Languages
- Prolog is a declarative logic language designed for artificial intelligence applications
- Learned the different types of coding applications.
Are these statements valid… Discuss.
Higher – Languages and Environments
JPG vs PNG vs GIF
Python on Raspberry Pi
For a bit of a change the class were programming in Python on a Raspberry Pi.
The program below was used to create a Gold Block in Minecraft.
1 2 3 4 5 6 7 8 |
from mcpi . minecraft import Minecraft import mcpi . block as block mc = Minecraft . create () pos = mc. player . getPos () x = pos.x y = pos.y z = pos.z mc. setBlock (x, y, z, block . GOLD_BLOCK .id) |
Created using http://hilite.me/ and http://www.geocraft.org.uk/
Higher Computing Science – Homework due 3/11/15
A quick revision of data types for homework this week.
Input Validation
Programmers need to make sure that the data they allow into their programs is sensible. They can use input validation to check that the data is within a range.
Array Handling
In Python array handling can be accomplished by using Python’s built in list comprehension. This means when we are working with arrays we need to change the way we use the for loop depending on whether we are interested in the value or the position of the value.
In the code above the first for loop is simply printing the value from the list. The second loop knows the position of each item and can therefore display that information as well.
Python Functions
A function is a predefined block of code which is used then programming. It often contains a number of commands and steps.
Here are some of the functions we have met
print()
This function displays the string that is contained in it parenthesis ().
print(‘Hi there, how are you?)
input()
This function displays the string in its parenthesis but allows the user to enter a string that is then returned and assigned to a variable.
age=input(‘What is your age?’)
str()
Converts the contents of its parenthesis to a string
check=input(‘Is your age ‘+str(age))
len()
Outputs the length (number of characters) of a string or the size (number of elements) in an array
print(‘The length of your name is’,len(name))
float()
Converts a value to a floating point number
weight=float(input(‘How many KG do you weight’))
int()
Converts a value to an integer
age=int(input(‘What is your age?’))
Import Function
Python is a general purpose language which means that it can be used to solve many different tasks. However Python does not have a command for every single eventuality. So programmers have created document with lots of different functions, these are called module libraries.
The import command is used to import module libraries into python programs.
The random module stores a number of functions, to get access to the function we want we must first import random then use dot notation to specify the function we want to call. So random.randint calls the randint function from the random module library we imported previously.
There are libraries to do many things and they all should come with documentation to make them easy to use. Like all python programs they are open source so you can have a look inside to see how they work. Here are some example