State and Types


You have been introduced to state with examples in the lecture, i.e. the lightbulb and traffic lights. This week’s labs build on the concept of states and allow you to explore how abstract objects are given a state by defining attributes and assigning values to those attributes.

In the lightbulb example, the state was either on or off. In the traffic light example, there were more than 2 possible states. There were more possible states because there were more attributes (three lights as opposed to one).

An objects state may be in one of many combinations, let’s consider a simple binary example: a binary bit can only be in one of two states, either 1 or 0, but if we have two binary bits and group them together we introduce more possible states: 00, 01, 10 and 11.

When defining a state, we are interested in the values associated with the attributes, let’s come back to our traffic light example, our attributes are red light, yellow light and green light and the states are on or off (to keep things simple). How many different states could there be?

image

Open Code Editor






Click here to go to the COMP16321 Blackboard page


Click anywhere to close this video

Contents



Introduction

Exercises

Conclusion


Green = Current Page

Click anywhere to close this overlay

Topics Covered in this Lab



1. Variables (declaration, initialisation and assignment)

2. Types (string, boolean, integer, float and complex numbers)

3. State (The state of an object given its variable values)

4. The + operator (addition and concatenation)

5. Other operators (*, **, % and /)

6. Basic Functions (print(), type(), str(), int())

7. Debugging

8. The array (list) operator

9. The range : operator

10. The equality operator

11. Evaluating boolean expresions



Click anywhere to close this overlay

Lab Key



Notes – #FF6F61

Videos – #34568B

Code Examples – #009B77

Downloads - #C3447A

Internal Link (University Resources) – #955251

External Link (Non-University Resources)– #EFC050

Other - #660099



Click anywhere to close this overlay