Basic Syntax

Learn the fundamental syntax of SAPL

Comments

Comments in SAPL start with the # character. They are ignored by the interpreter and are used to add notes or explanations to your code.

# ይህ አንድ አስተያየት ነው
# This is a comment

አሳይ("ሰላም") # ይህ ኮድ ሰላም ይላል
SAPL

Statements

Each statement in SAPL is written on a separate line. A statement is a complete instruction that the SAPL interpreter can execute.

ስም = "አበበ"
እድሜ = 25
አሳይ(ስም)
አሳይ(እድሜ)
SAPL

Indentation

Like Python, SAPL uses indentation to define code blocks. The standard indentation is 4 spaces. Proper indentation is crucial for the interpreter to understand the structure of your code.

ለ ቁጥር በ ውስጥ(1, 5):
    አሳይ("ቁጥር " + ቁጥር)
    እድሜ = ቁጥር * 10
    አሳይ("እድሜ " + እድሜ)
SAPL

In the example above, the indented lines are part of the loop block. The indentation clearly shows which statements are executed within the loop.

To display output, use the አሳይ() function. This function prints the specified message to the console.

አሳይ("ሰላም ዓለም!")
ስም = "ሰሎሞን"
አሳይ("ሰላም, " + ስም + "!")
SAPL

The አሳይ() function can display strings, numbers, variables, and the results of expressions.

Variables

Variables are used to store data values. In SAPL, you can create a variable by assigning a value to it using the equals sign (=).

# Variable assignment
ስም = "አበበ"
እድሜ = 25
ቁጥር = 3.14
እውነት_ነው = እውነት

# Using variables
አሳይ(ስም)
አሳይ(እድሜ)
አሳይ(ቁጥር)
አሳይ(እውነት_ነው)
SAPL

Variable names in SAPL can contain letters, numbers, and underscores, but they must start with a letter or an underscore. They are case-sensitive, meaning ስም and ስም are considered different variables.

Basic Operators

SAPL supports standard arithmetic operators for performing calculations. These operators work with numbers and, in some cases, with strings.

# Arithmetic operations
ቁጥር1 = 10
ቁጥር2 = 5

ድምር = ቁጥር1 + ቁጥር2      # 15
ልዩነት = ቁጥር1 - ቁጥር2     # 5
ብዜት = ቁጥር1 * ቁጥር2     # 50
ክፍፍል = ቁጥር1 / ቁጥር2    # 2.0
ሞዱሎ = ቁጥር1 % ቁጥር2     # 0
ኃይል = ቁጥር1 ** ቁጥር2    # 100000
SAPL
OperatorDescriptionExample
+Addition5 + 3 results in 8
-Subtraction5 - 3 results in 2
*Multiplication5 * 3 results in 15
/Division5 / 3 results in 1.6666...
%Modulus (remainder)5 % 3 results in 2
**Exponentiation5 ** 3 results in 125

String Operations

Strings in SAPL are sequences of characters enclosed in quotation marks. You can use either single quotes (') or double quotes (") to define strings.

# String concatenation
ስም = "አበበ"
ሰላምታ = "ሰላም, " + ስም + "!"
አሳይ(ሰላምታ)  # ሰላም, አበበ!

# String repetition
ድግግሞሽ = "አበበ " * 3
አሳይ(ድግግሞሽ)  # አበበ አበበ አበበ
SAPL

The + operator concatenates (joins) strings, while the * operator repeats a string a specified number of times.

Input

To get user input, use the ጠይቅ() function. This function displays a prompt to the user and waits for them to enter a value.

ስም = ጠይቅ("ስምህን አስገባ: ")
አሳይ("ሰላም, " + ስም + "!")
SAPL

The ጠይቅ() function always returns a string. If you need a number, you'll need to convert the input using functions like ቁጥር() (for integers) or ነጥብ_ቁጥር() (for floating-point numbers).

እድሜ_ፅሁፍ = ጠይቅ("እድሜህን አስገባ: ")
እድሜ = ቁጥር(እድሜ_ፅሁፍ)
አሳይ("ቀጣዩ ዓመት እድሜህ " + (እድሜ + 1) + " ይሆናል።")
SAPL

Comparison Operators

Comparison operators are used to compare values. They return either እውነት (true) or ሐሰት (false).

ቁጥር1 = 10
ቁጥር2 = 5

አሳይ(ቁጥር1 == ቁጥር2)  # ሐሰት (false)
አሳይ(ቁጥር1 != ቁጥር2)  # እውነት (true)
አሳይ(ቁጥር1 > ቁጥር2)   # እውነት (true)
አሳይ(ቁጥር1 < ቁጥር2)   # ሐሰት (false)
አሳይ(ቁጥር1 >= ቁጥር2)  # እውነት (true)
አሳይ(ቁጥር1 <= ቁጥር2)  # ሐሰት (false)
SAPL
OperatorDescriptionExample
==Equal to5 == 5 is እውነት
!=Not equal to5 != 3 is እውነት
>Greater than5 > 3 is እውነት
<Less than5 < 3 is ሐሰት
>=Greater than or equal to5 >= 5 is እውነት
<=Less than or equal to5 <= 3 is ሐሰት

Logical Operators

SAPL uses Amharic words for logical operators. These operators are used to combine conditional statements.

ሁኔታ1 = እውነት
ሁኔታ2 = ሐሰት

አሳይ(ሁኔታ1 እና ሁኔታ2)    # ሐሰት (false)
አሳይ(ሁኔታ1 ወይም ሁኔታ2)  # እውነት (true)
አሳይ(አይደለም ሁኔታ1)     # ሐሰት (false)
SAPL
OperatorDescriptionExample
እናLogical ANDእውነት እና እውነት is እውነት
ወይምLogical ORእውነት ወይም ሐሰት is እውነት
አይደለምLogical NOTአይደለም እውነት is ሐሰት