-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4d10d74
commit 890a4b0
Showing
9 changed files
with
714 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,122 @@ | ||
# Orodha (Arrays) | ||
# Orodha Au Safu Katika Nuru | ||
|
||
Safu katika nuru ni miundo ya data ambayo inaweza kubeba vitu vingi, ikiwa ni pamoja na aina za data tofauti tofauti kama `namba`, `tungo`, `buliani`, `vitendakazi`, na thamani `tupu`. Ukurasa huu unaangazia vipengele mbalimbali vya safu, ikiwemo namna ya kutengeneza, kuchambua, na kuzunguka ndani yake kwa kutumia vitendakazi vilivyojengwa ndani ya Nuru. | ||
|
||
## Kutengeneza Safu | ||
|
||
Kutengeneza safu, tumia mabano mraba na tenganisha kila kitu kimoja kwa kutumia mkwaju: | ||
|
||
```s | ||
orodha = [1, "pili", kweli] | ||
``` | ||
|
||
## Kupata na Kubadilisha Vipengele vya Safu | ||
|
||
Safu katika Nuru ni zero-indexed; ikimaanisha kipengele cha kwanza katika safu kina kumbukumbu namba 0. Kupata kipengele, unaweza ukatumia kumbukumbu namba yake ndani ya mabano mraba: | ||
|
||
```s | ||
namba = [10, 20, 30] | ||
jina = namba[1] // jina is 20 | ||
``` | ||
|
||
Unaweza ukabadilisha kipengele katika safu kwa kutumia kumbukumbu namba yake: | ||
|
||
```s | ||
namba = [10, 20, 30] | ||
namba[1] = 25 | ||
andika(namba) // Tokeo: [10,25,30] | ||
``` | ||
|
||
## Kuunganisha Safu | ||
|
||
Kuunganisha safu mbili au zaidi, tumia kiendeshi `+`: | ||
|
||
```s | ||
a = [1, 2, 3] | ||
b = [4, 5, 6] | ||
c = a + b | ||
// c is now [1, 2, 3, 4, 5, 6] | ||
``` | ||
|
||
## Kuangalia Uanachama Katika Safu | ||
|
||
Tumia neno msingi `ktk` kuangalia kama kipengele kipo ndani ya safu: | ||
|
||
```s | ||
namba = [10, 20, 30] | ||
andika(20 ktk namba) // Tokeo: kweli | ||
``` | ||
|
||
## Kuzunguka Ndani ya Safu | ||
|
||
Unaweza kutumia maneno msingi `kwa` na `ktk` kuzunguka ndani ya safu. Kuzunguka ndani ya safu na kupata kipengele peke yake tumia sintaksia ifuatayo: | ||
|
||
```s | ||
namba = [1, 2, 3, 4, 5] | ||
kwa thamani ktk namba { | ||
andika(thamani) | ||
} | ||
//Tokeo: | ||
1 | ||
2 | ||
3 | ||
4 | ||
5 | ||
``` | ||
|
||
Kuzunguka ndani ya safu na kupata kumbukumbu namba na kipengele tumia sintaksi aifuatayo: | ||
|
||
```s | ||
majina = ["Juma", "Asha", "Haruna"] | ||
kwa idx, jina ktk majina { | ||
andika(idx, "-", jina) | ||
} | ||
//Tokeo: | ||
0-Juma | ||
1-Asha | ||
2-Haruna | ||
``` | ||
|
||
## Vitendakazi vya Safu | ||
|
||
Nuru ina vitendakazi mbalimbali vilivyojengwa ndani kwa ajili ya Safu: | ||
|
||
### idadi() | ||
|
||
`idadi()` hurudisha urefu wa safu: | ||
|
||
```s | ||
a = [1, 2, 3] | ||
urefu = a.idadi() | ||
andika(urefu) // Tokeo: 3 | ||
``` | ||
|
||
### sukuma() | ||
|
||
`sukuma()` huongeza kipengele kimoja au zaidi mwishoni mwa safu: | ||
|
||
```s | ||
a = [1, 2, 3] | ||
a.sukuma("s", "g") | ||
andika(a) // Tokeo [1, 2, 3, "s", "g"] | ||
``` | ||
|
||
### yamwisho() | ||
|
||
`yamwisho()` hurudisha kipengele cha mwisho katika safu, au `tupu` kama safu haina kitu: | ||
|
||
```s | ||
a = [1, 2, 3] | ||
mwisho = a.yamwisho() | ||
andika(mwisho) // Tokeo: 3 | ||
b = [] | ||
mwisho = b.yamwisho() | ||
andika(mwisho) // Tokeo: tupu | ||
``` | ||
|
||
Kwa kutumia taarifa hii, unaweza ukafanyakazi na safu za Nuru kwa ufanisi, kufanya iwe rahisi kuchambua mikusanyo ya data katika programu zako. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,97 @@ | ||
# Kweli/Sikweli (Bools) | ||
# Kufanya Kazi na Buliani Katika Nuru | ||
|
||
Vitu vyote katika Nuru ni kweli, yaani thamani yoyote ni kweli isipokua tupu and sikweli. Hutumika kutathmini semi ambazo zinarudisha kweli au sikweli. | ||
|
||
## Kutathmini Semi za Buliani | ||
|
||
### Kutathmini Semi Rahisi | ||
|
||
Katika Nuru, unaweza kutathmini semi rahisi zinazorudisha thamani ya buliani: | ||
|
||
```go | ||
andika(1 > 2) // Matokeo: `sikweli` | ||
|
||
andika(1 + 3 < 10) // Matokeo: `kweli` | ||
``` | ||
|
||
### Kutathmini Semi Tata | ||
|
||
Katika Nuru, unaweza kutumia viendeshaji vya buliani kutathmini semi tata: | ||
|
||
```go | ||
a = 5 | ||
b = 10 | ||
c = 15 | ||
|
||
tokeo = (a < b) && (b < c) | ||
|
||
kama (tokeo) { | ||
andika("Hali zote mbili ni kweli") | ||
} sivyo { | ||
andika("Angalau hali moja ni sikweli") | ||
} | ||
// Tokeo: "Hali zote mbili ni kweli" | ||
``` | ||
|
||
Hapa tumetengeneza vibadilika vitatu a,b,c. Kisha tukatathmini semi (a < b) && (b < c). Kwa sababu semi zote mbili ni kweli, tokeo litakua "Hali zote mbili ni kweli". | ||
|
||
## Vitendakazi vya Buliani | ||
|
||
Nuru ina vitendakazi vya buliani kadhaa ambavyo unaweza ukatumia kutathmini semi: | ||
|
||
### Kitendakazi `&&` | ||
|
||
Kitendakazi `&&` hutathmini kwenda kweli kama tu vitu vyote vinavyohusika ni kweli. Kwa mfano: | ||
|
||
```go | ||
andika(kweli && kweli) // Tokeo: `kweli` | ||
|
||
andika(kweli && sikweli) // Tokeo: `sikweli` | ||
``` | ||
|
||
### Kitendakazi `||` | ||
|
||
Kitendakazi || hutathmini kwenda kweli kama angalau kitu kimoja kati ya vyote vinavyohusika ni kweli. Kwa mfano: | ||
|
||
```go | ||
andika(kweli || sikweli) // Tokeo: `kweli` | ||
|
||
andika(sikweli || sikweli) // Tokeo: `sikweli` | ||
``` | ||
|
||
### Kitendakazi `!` | ||
|
||
Kitendakazi `!` hukanusha thamani ya kitu. Kwa mfano: | ||
|
||
```go | ||
andika(!kweli) // Tokeo: `sikweli` | ||
|
||
andika(!sikweli) // Tokeo: `kweli` | ||
``` | ||
|
||
## Kufanya Kazi na Thamani za Buliani Katika Vitanzi | ||
|
||
Katika Nuru, unaweza ukatumia semi za buliani katika vitanzi kuendesha tabia zake. Kwa mfano: | ||
|
||
```go | ||
namba = [1, 2, 3, 4, 5] | ||
|
||
kwa thamani ktk namba { | ||
kama (thamani % 2 == 0) { | ||
andika(thamani, " ni namba shufwa") | ||
} sivyo { | ||
andika(thamani, " ni namba witiri") | ||
} | ||
} | ||
|
||
// Output: | ||
// 1 ni namba witiri | ||
// 2 ni namba shufwa | ||
// 3 ni namba witiri | ||
// 4 ni namba shufwa | ||
// 5 ni namba witiri | ||
``` | ||
|
||
Hapa , tumetengeneza safu yenye namba 1 hadi 5 kisha tukazunguka ndani ya safu hiyo na kwa kila namba tukatumia kitendakazi `%` ilikubaini kama namba ni shufwa au witiri. Matokeo yatakua ni "ni namba shufwa" kwa namba shufwa na "ni namba witiri" kwa namba witiri. | ||
|
||
Vitu buliani katika Nuru vinaweza kutumika kutathmini semi ambazo zinarudisha thamani ya kweli au sikweli. Unaweza kutumia vitendakazi vya buliani kutathmini semi tata na kuendesha tabia ya vitanzi. Kuelewa namna ya kufanya kazi na thamani za buliani ni ujuzi wamsingi kwa mtengenezaji programu yeyote wa Nuru. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,54 @@ | ||
# Builtins | ||
# Vitendakazi Vilivyojengwa Ndani ya Nuru | ||
|
||
Nuru ina vitendakazi kadhaa vilivyojengwa ndani vinavyofanya kazi husika. | ||
|
||
## Kitendakazi andika() | ||
|
||
Kitendakazi `andika()` kinatumika kuchapisha ujumbe kwenye konsoli. Inawezakuchukua hoja sifuri au zaidi, na hoja zitachapishwa na nafasi kati yao. Kwa kuongeza, `andika()` huhimili uundaji wa msingi kama vile `/n` kwa ajili ya mstari mpya, `/t` kwa ajili ya nafasi ya kichupo, na `\\` kwa ajili ya mkwajunyuma. Mfano: | ||
|
||
```go | ||
andika(1, 2, 3) // Output: 1 2 3 | ||
``` | ||
|
||
```go | ||
andika("Jina: Asha /n Umri: 20 /n Chuo: IFM") | ||
|
||
// Output: | ||
// Jina: Asha | ||
// Umri: 20 | ||
// Chuo: IFM | ||
``` | ||
|
||
## Kitendakazi jaza() | ||
|
||
Kitendakazi `jaza()` kinatumika kupata ingizo kutoka kwa mtumiaji. Inawezakuchukua hoja sifuri au moja, ambayo ni utungo utakao tumika kama kimahasishi kwa mtumiaji. Mfano: | ||
|
||
```go | ||
fanya salamu = unda() { | ||
fanya jina = jaza("Unaitwa nani? ") | ||
andika("Mambo vipi", jina) | ||
} | ||
|
||
salamu() | ||
``` | ||
|
||
Katika mfano huu, tunaainisha kitendakazi `salamu()` ambacho kinamhamasisha mtumiaji kuingiza jina kwa kutumia kitendakazi `jaza()`. Kisha tunatumia kitendakazi `andika()` kuchapisha ujumbe unaobeba jina la mtumiaji aliloingiza. | ||
|
||
## Kitendakazi aina() | ||
|
||
Kitendakazi `aina()` kinatumika kutambua aina ya kitu. Inakubali hoja moja, na thamani inayorudi hua ni utungo unaoonyesha aina ya kitu. Mfano: | ||
|
||
```go | ||
aina(2) // Output: "NAMBA" | ||
aina("Nuru") // Output: "NENO" | ||
``` | ||
|
||
## Kitendakazi fungua() | ||
|
||
Kitendakazi `fungua()` kinatumika kufungua faili. Inakubali hoja moja, ambayo ni njia ya faili unalotaka kufungua. Mfano: | ||
|
||
```go | ||
faili = fungua("data.txt") | ||
``` | ||
|
||
Katika mfano huu, tumetumia kitendakazi `fungua()` kufungua faili linaloitwa "data.txt". Kibadilika `faili` kinabeba kumbukumbu ya faili lililofunguliwa. |
Oops, something went wrong.