Tutorial Python untuk bukan pengatur cara/Menangani kecacatan: Perbezaan antara semakan

Kandungan dihapus Kandungan ditambah
Algazel (bincang | sumb.)
kembang terjemahan
Algazel (bincang | sumb.)
kembang
Baris 52:
except ValueError:
print "Ralat. Sila masukkan nilai integer."
yeartahun = 0
except NameError:
print "Ralat. Sila masukkan nilai integer."
yeartahun = 0
except SyntaxError:
print "Ralat. Sila masukkan nilai integer."
yeartahun = 0
finally:
print "Program Selesai"
Baris 73:
</source>
 
Pengaturcaraan di atas menggunakan konsep-konsep daripada pelajaran dahulu dan juga pelajaran semasa.
The program above uses concepts from previous lessons as well as the current lesson.
Let's look at the above program in sections.
 
Mari kita lihat bahgian-bahagian program di atas.
After we define the function called "main", we tell it that we want to "try" function named "epact". It does so "while" there is no "success". The interpreter then goes to the the line <code>year = int(input("What year is it?\n"))</code>.
 
The interpreter takes the value entered by the user and stores it in the variable named "year".
Selepas kita memberi definisi fungsi bernama "utama", kita memberitahu program bahawa kita mahu ia "mencuba" fungsi yang bernama "epak". Ia melakukannya "sementara" (''while'') ia tidak "berjaya". Pentafsir kemudian pergi ke baris <code>tahun = int(input("Ini tahun apa?\n"))</code>. Pentafsir kemudiannya mengambil nilai yang dimasukkan pengguna dan menstor nilai tersebut dalam sebuah pemboleh ubah bernama "tahun".
 
If the value entered is not an integer or a floating point number (which would be converted to an integer by the interpreter), an exception would be raised, and execution of the <code>try</code> block ends, just before <code>success</code> is assigned the value 1.