Tutorial Python untuk bukan pengatur cara/Contoh Fungsi Lanjutan: Perbezaan antara semakan

Kandungan dihapus Kandungan ditambah
Algazel (bincang | sumb.)
→‎Contoh: terjemah contoh
Algazel (bincang | sumb.)
kembang
Baris 30:
return 0
baki = mult(a, b - 1)
valuenilai = a + baki
return valuenilai
</source>
}}
Baris 47:
----
 
'''RUNPELAKSANAAN 2'''
; Apa yang berlaku kemudiannya?
; What happens next?
: ThePemboleh variableubah <code>a</code> getsmenerima the valuenilai 3 assignedyang todiumpukkan itkepadanya anddan thepemboleh variableubah <code>b</code> getsmenerima the valuenilai 2 assigned to it.
----
; And thenKemudian?
: The lineBaris <code>if b == 0:</code> is rundilaksanakan. SinceOleh sebab <code>b</code> hasmempunyai the valuenilai 2, thisini isbermaksud falsePalsu, sojadi the linebaris <code>return 0</code> is skippeddilangkau.
----
; AndDan what thenkemudian?
: The lineBaris <code>restbaki = mult(a, b - 1)</code> is rundilaksanakan. ThisBaris lineini setsmenetapkan thepemboleh localubah variablelokal <code>restbaki</code> tokepada the value ofnilai <code>mult(a, b - 1)</code>. The value ofNilai <code> a</code> isadalah 3 anddan the value ofnilai <code> b</code> isadalah 2 so thejadi functionpanggilan callfungsi isadalah <code>mult(3,1)</code>
----
; SoJadi whatapa ispula the value ofnilai <code>mult(3, 1)</code> ?
: WeKita willperlu needmelaksanakan to run the functionfungsi <code> mult</code> with thedengan parametersparameter 3 anddan 1.
{{Penyelesaian|tajuk=PELAKSANAAN 2|teks=
{{Solution|title=RUN 2|text=
<source lang="python">
def mult(3, 2):
if b == 0:
return 0
restbaki = mult(3, 2 - 1)
restbaki = mult(3, 1)
valuenilai = 3 + restbaki
return valuenilai
</source>
}}
 
----
'''RUNPELAKSANAAN 3'''
; Apa yang berlaku seterusnya?
; So what happens next?
: ThePemboleh localubah variableslokal indalam thepelaksanaan '' newbaru'' run of the function are setfungsi soditetapkan thatagar <code>a</code> hasmemiliki the valuenilai 3 anddan <code> b</code> hasmemiliki the valuenilai 1. SinceMemandangkan thesebahawa areini localadalah valuesnilai-nilai theselokal, donilai-nilai notini affecttidak themenjejaskan previous values ofnilai-nilai <code>a</code> anddan <code>b</code> sebelum ini.
----
; And thenKemudian?
: SinceOleh sebab <code> b</code> hasmemiliki the valuenilai 1, thekenyataan <code>if</code> statement ismenjadi falsePalsu, so thejadi nextbaris lineberikutnya becomesmenjadi <code>restbaki = mult(a, b - 1)</code>.
----
; WhatApa doesyang thisdilakukan linebaris doini?
: ThisBaris lineini willakan assignmengumpukkan the value ofnilai <code>mult(3, 0)</code> tokepada restbaki.
----
; Apakah nilai itu?
; So what is that value?
: WeKita willperlu havemelaksanakan tokod runsekali thelagi functionbagi onemendapatkan morejawapannya. timeKali toini find that out. This timenilai <code>a</code> hasadalah the3 valuedan 3 andnilai <code>b</code> has the valueadalah 0.
----
; So what happens next?