PowerPoint Presentation
Basics in programming
Lectures 3
Basics of pseudo-coding
Comments and variables
Getting started with Python
What’s pseudo-coding
Idea / Problem
Solution / Plan
Pseudo-code
Code
Pseudo-code what is it?
-Design the solutions to problems without actually knowing how to code
-Logic of your solution to a specific coding challenge using natural language
-You can use pseudo-code when even without knowing what your programming language will be
Pseudo-code
-There is no strict definition of how pseudo code should look like or how its should be written
Pseudo-code
Pseudo-code
Pseudo-code, example?
-Explain how ATM machine works for general audience
Pseudo-code
-Pseudo-code can be used when planning program logic or in some parts of the program.
-Algorithms for example expressed in pseudo-code
Pseudo-code, example 2.
-Write pseudo code that inverts binary image
Pseudo-code why to use it?
-Focuses on the building block concepts of programming languages without you having to worry about whether you are using the “right” words.
-Represents wireframe or template of your code, and can easilly be turned into chosen programming language
Pseudo-code, on class exercise 1
-Write program that calculate biggest of three numbers
Pseudo-code, on class exercise 2
-Write on program that makes coffee
Pseudo-code
See Code Complete 2:
Pages 215 – 236
Basics concepts of programming
Commenting
While using comments you actually leave cues to reader of what code does
These comments can be for yourself or for other programmers who will look at your code.
Comments are not read by any compiler or interpreter while processing code — they are there entirely for the benefit of humans reading the code.
Basics concepts of programming
Commenting – C++ / JAVA
Basics concepts of programming
Commenting – Python
Basics concepts of programming
See Code Complete 2:
Pages 781 – 792
Basics concepts of programming
Variables
Variables are the names you give to computer memory locations which are used to store values in a computer program.
Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory.
Variables – What are they
Cornerstone of any program as they allow you to work and manipulate data in computers memory
Variable is actually a address in memory of computer where data is stored.
Lets explain this…
Variables – What are they
Variables – What are they
Program loads data into variable, now it can be manipulated
If variable has no value, its NULL (null), and waits to be loaded. This is called initialisation
Some program languages automatically initialise values as 0/false or NULL
Variables – What are they
Variable can hold different kind of data
Number (integers / floating points)
Characters
Strings
Boolean values
Variables – What are they
The great thing about variables is that they are very versatile.
You can easily change what the variable holds.
Variables – What are they
Javascript
Java/C++
Python
Variables – What are they
In memory, variables are stored in their own ”boxes”
Variables – What are they
Some languages have implicit variable declarations.
For example, if you use a variable in Microsoft Visual Basic without declaring it, the compiler declares it for you automatically, same applies to Python but not to C/C++
-> This can easily lead into problems
Variables – What are they
Some tips:
Turn off implicit declarations
Declare all variables and initialise them
Use naming conventions
Using each variable for exactly one purpose
Keep variable lifespan short
Variables – What are they
See Code Complete 2, PART 3
Variables – What are they
Now lets use variables in Python
Python
Python is object-orientated programming language with easy-to-use syntax.
Python has become popular during last years. Widely used in scientific applications, IoT-devices, data-analytics and artificial intelligence
Python
Python
Python
Run Python IDLE from start menu
Create new File with content
print(’Hello World!’)
Save the file as first_program.py
Run program by choosing Run -> Run Modul
Python
Declare few variables and assign values to them:
counter = 1
kilometers = 15.6
name = ’Jari’
Python variables do not need explicit declaration to reserve memory space. The declaration happens automatically when you assign a value to a variable. The equal sign (=) is used to assign values to variables.
Python
Print values of these variables:
print(counter)
print( kilometers)
print( name)
Python
Basic Python datatypes:
Integers
Floating-Point Numbers
Complex Numbers
Strings
Boolean
type()-function can be used to check datatype
Python
Lets create program that declares 5 number variables and calculates sum of these.
And 5 string values which are concatenated
Then we print one string value and one number value
Python
https://realpython.com/python-data-types
Exercise 3.
Write pseudo code for following:
Explain how a vending machine program works to a general audience via pseudo-code
Write python application that sums five numbers and prints their sum
Next classes
C/C++ demonstration of variables
Number Representations
Working with Strings
Reference Types
Code Structure
Input / Output
Decission making
/docProps/thumbnail.jpeg