Selection ... choices

Things to debate - Remember.


Comments

C

#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
  int cats = atoi(argv[1]);
  if (cats > 3) {
    printf ("%d is too many cats\n", cats);
  } else {
    printf ("%d cats is OK\n", cats);
  }
}

Python

import sys
cats = int(sys.argv[1])
if cats > 3:
  print("%d is too many cats" %(cats))
else:
  print("%d cats is OK" %(cats))

Bash

if [ $1 -gt 3 ];
then
  echo $1 is too many cats
else
  echo $1 cats is OK
fi

PHP

<?php
$cats = $_SERVER['QUERY_STRING'];
if ($cats > 3) {
  echo "$cats is too many cats\n";
} else {
  echo "$cats cats is OK\n";
}
?>

Hands On

Copy the above code into the respective files:

Run the programs


Homework

Choose 2 of the 4 languages and write some simple selection code that does something useful.
cpu=$(</sys/class/thermal/thermal_zone0/temp)
echo "$((cpu/1000)) c"

On the Pi running Raspbian the temperature can be found at at the same place


Appendix

Date and time