58 - Using Multiple elif Blocks & Omitting the else Block.

Опубликовано: 29 Июль 2026
на канале: القبعة البيضاء
180
12

You can use as many elif blocks in your code as you like. For example,
if the amusement park were to implement a discount for seniors, you
could add one more conditional test to the code to determine whether
someone qualified for the senior discount. Let’s say that anyone 65 or
older pays half the regular admission, or $20

Python does not require an else block at the end of an if-elif chain.
Sometimes an else block is useful; sometimes it is clearer to use an
additional elif statement that catches the specific condition of interest

"يمكنك استخدام العديد من كتل `elif` في الكود الخاص بك كما تريد. على سبيل المثال، إذا أراد متنزه ترفيهي تقديم خصم لكبار السن، يمكنك إضافة اختبار شرطي آخر للكود لتحديد ما إذا كان الشخص مؤهلاً للحصول على خصم كبار السن. لنفترض أن أي شخص يبلغ من العمر 65 عامًا أو أكثر يدفع نصف سعر التذكرة العادي، وهو 20 دولارًا.

لا يتطلب بايثون وجود كتلة `else` في نهاية سلسلة `if-elif`. في بعض الأحيان تكون كتلة `else` مفيدة؛ وفي أحيان أخرى يكون من الواضح أكثر استخدام تعبير `elif` إضافي يتناول الشرط المحدد المعني.

57 - Copying and Erasing Configuration Files.
   • 57 - Copying and Erasing Configuration Files.