Simple programming exercies

Simple programming exercises

Basic control structures and variables

  1. Write a program that prints ‘Hello World’ to the screen.
  2. Write a program that asks the user for their name and greets them with their name.
  3. Modify the previous program such that only the users Alice and Bob are greeted with their names.
  4. Write a program that asks the user for a number n and prints the sum of the numbers 1 to n

Above exercises by Adrian Neumann, CC-BY-SA

Hints

  • Reading string input: local myString = io.read()
  • Reading number input: local myNumber = io.read("*n")
  • if statements (exercise 3) see PIL chapter 4.3.1
  • Numeric for loops (exercise 4) see PIL chapter 4.3.4

Tables

  1. Store the pitch sequence of a melody in a table. Use numeric values like in MEI’s @pname attribute to represent the pitches.
  2. Print each pitch value in the table.
  3. Transpose the melody by changing each pitch value.

Hints