National 5 – Boolean

A boolean variable is used to store True or False values. This can be very useful in programs, as you can use it in the program logic.

In the example below the user has to choose to exit the program, this sets the quitProg boolean variable to True which makes the result of the condition in line 3 False. Notice that True/False have capitals at the start of the value.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
quitProg=False

while not quitProg:

    #Program does stuff here
    
    choice=input('Do you want to quit (Y/N):')
    if choice in 'Yy':
        quitProg=True

print('Exiting program')    

N5 & Higher – Input Validation (Python)

Input validation is used in both National 5 and at Higher. It consists of 3 parts.

  1. Get the user to enter a value
  2. While the value is wrong
  3.     Get the user to enter a value

The use of the while construct allows the program to repeatedly ask the user to enter valid data.

1
2
3
4
5
6
7
8
9
age=0

#Input Validation
age=int(input('Please enter your age>'))
while age<0 or age>120: # Check that age is between 0 and 120
    print('Please check your age is between 0 and 120')
    age=int(input('Please enter your age>'))
    
print('Welcome')

This can also be used with strings, can you work out how to modify the code so that it would only take a ‘Yes’ ‘No’ answer?

BGE – Top Trumps Database

BeanoToday we analysed a pack of top trumps Beano cards. Pupils were asked to identify field names and types. This was then put into a table before we created the database in Access.

How do you think you would turn this database into a game?

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

Today we were looking at all the many type of programming languages that are out there. Most have three things in common.

  • Sequence
  • Selection
  • Iteration

We then undertook some research and found out the following facts

lang

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/