Variables
Storing values, numbers, text and types
A variable is a name you give a value, so you can use it by name later.
አበበ 25
Names are written in Amharic: ስም (name), ዕድሜ (age), የተማሪ_ቁጥር
(student number) all work.
Changing a value
They are called variables because the value can change.
1
2
ቆጣሪ = ቆጣሪ + 1 means "take what ቆጣሪ holds now, add one, and put the
result back into ቆጣሪ".
Types of value
Ahadu has four basic types. The አይነት function — "type" — tells you which
one you have.
ቁጥር
ጽሁፍ
እውነታ
ስብስብ
Those are number, text, truth and collection.
Those four names — ቁጥር, ጽሁፍ, እውነታ, ስብስብ — belong to the language,
so they cannot be used as variable names:
[AH2001] የተለዋጭ ስም ይጠበቃል።: መስመር 1 ላይ: 5ኛው ካራክተር
Pick something else, like አሃዝ or ተራ.
Arithmetic
Numbers take the usual operators.
9
5
14
3.5
1
% gives the remainder — 7 divided by 2 leaves 1. It is how you test whether
a number is even.
Joining text
On text, + joins.
ተስፋማርያም
A number and a piece of text cannot be added, though. This is an error:
[AH3002] ጽሁፍ እና ቁጥርን መደመር አይቻልም።: መስመር 1 ላይ: 4ኛው ካራክተር
The message says what went wrong. If you want both on one line, pass them as
two values instead: ጻፍ("ዕድሜ፦"፣ 25).
Exercise
Work out the area and the perimeter of a rectangle 7 long and 4 wide.
Show the answer
ስፋት፦ 28
ዙሪያ፦ 22