Computer programming

Think Pair Share

  1. What is software?
  2. What is computer programming?

Some examples of computer programming languages

  • C++
  • Javascript
  • Python
  • Scratch
#include <iostream>
using namespace std;
int main()
{
    cout<<"Hello World!";
    return 0;
}
var http = require('http');

var server = http.createServer(function(req, res) {
  res.writeHead(200);
  res.end('Hello Http');
});
server.listen(8080);

Why Python?

http://repl.it

  • Register with your gmail account
  • Make sure your username is recognizable
  • Don't forget your password!
print('Hello World')

Flow chart

What is the expected output of this?

Variables and calculations

# This is comment
# Computer will ignore these lines

# Assign 12 to a new variable
A = 12

print(A)

Start a new REPL and name it VariablesExercise

Variable

  • Variable is like a box to store a given value
  • You can put new value into it but the old one will be discarded
  • You are free to name the variable (only very few words are not allowed), but make sure it is meaningful
  • No space in variable name, we usually use CamelCaseNaming to name variables

Exercise

  1. Create another variable called B
  2. Assign any number to it
  3. Print out the value of B
# Modify the lines of print to:
Print('Value of A is:', A)
Print('Value of B is:', B)

Exercise

  • Can you try to print out the followings:
    • Sum of A and B
    • Difference of A and B
    • Multiply of A and B
    • A divided by B
  • Make sure you have properly labelled your outputs

Random function

Made with Slides.com