Ahadu 2.0
አማርኛ

Variables

Storing values, numbers, text and types

A variable is a name you give a value, so you can use it by name later.

Open in playground This output was verified at build time
አበበ 25

Names are written in Amharic: ስም (name), ዕድሜ (age), የተማሪ_ቁጥር (student number) all work.

Changing a value

They are called variables because the value can change.

Open in playground This output was verified at build time
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.

Open in playground This output was verified at build time
ቁጥር
ጽሁፍ
እውነታ
ስብስብ

Those are number, text, truth and collection.

Those four names — ቁጥር, ጽሁፍ, እውነታ, ስብስብ — belong to the language, so they cannot be used as variable names:

Open in playground This program fails on purpose
[AH2001] የተለዋጭ ስም ይጠበቃል።: መስመር 1 ላይ: 5ኛው ካራክተር

Pick something else, like አሃዝ or ተራ.

Arithmetic

Numbers take the usual operators.

Open in playground This output was verified at build time
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.

Open in playground This output was verified at build time
ተስፋማርያም

A number and a piece of text cannot be added, though. This is an error:

Open in playground This program fails on purpose
[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
Open in playground This output was verified at build time
ስፋት፦ 28
ዙሪያ፦ 22