Simple programming exercises
Basic control structures and variables
- Write a program that prints ‘Hello World’ to the screen.
- Write a program that asks the user for their name and greets them with their name.
- Modify the previous program such that only the users Alice and Bob are greeted with their names.
- Write a program that asks the user for a number
n
and prints the sum of the numbers 1 ton
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
- Store the pitch sequence of a melody in a table. Use numeric values like in MEI’s
@pname
attribute to represent the pitches. - Print each pitch value in the table.
- Transpose the melody by changing each pitch value.
Hints
- Storing sequences (exercise 1) see PIL chapter 11.1
- Iterate over tables using the
ipairs()
function (exercise 2; for more detailed info see PIL chapter 7.3).