def wage(hours: float, per_hour_rate: float) -> float:
return hours * per_hour_rate
print(wage(10, 50))
print(wage(3.5, 120))500
420.0
عدد المسائل: 8 الوقت التقديري: 45–60 دقيقة
ترتيب الحلول يطابق مسائل مسائل الدوال من الأسهل إلى الأصعب.
الفكرة: ضرب عدد الساعات في سعر الساعة.
الفكرة: إضافة فرق السنوات إلى العمر الحالي.
الفكرة: 40 - len(text) مسافة ثم النص.
الفكرة: حلقة for وrange(1, height + 1).
الفكرة: صفٌّ خارجي للارتفاع، وكل صف يكرّر الحرف بعرض width.
الفكرة: أربعة أسطر ثابتة الشكل مع استخدام number وnumber - 1.
99 cups of tea on the tray
99 cups of tea
Pour one out, pass it around
98 cups of tea on the tray
مثال: طباعة عدة أبيات متتابعة:
5 cups of tea on the tray
5 cups of tea
Pour one out, pass it around
4 cups of tea on the tray
4 cups of tea on the tray
4 cups of tea
Pour one out, pass it around
3 cups of tea on the tray
3 cups of tea on the tray
3 cups of tea
Pour one out, pass it around
2 cups of tea on the tray
2 cups of tea on the tray
2 cups of tea
Pour one out, pass it around
1 cups of tea on the tray
1 cups of tea on the tray
1 cups of tea
Pour one out, pass it around
0 cups of tea on the tray
الفكرة: تطبيق صيغة فيثاغورس.
الفكرة: شرط متداخل — الرصيد أولًا، ثم توفر النقود في الصراف.
def withdraw_cash(balance: float, amount: float, atm_cash: float) -> None:
if balance >= amount:
if atm_cash >= amount:
print('Withdrawal successful!')
else:
print('ATM does not have enough cash.')
else:
print('Insufficient balance.')
withdraw_cash(500, 200, 1000)
withdraw_cash(500, 200, 100)
withdraw_cash(500, 600, 1000)Withdrawal successful!
ATM does not have enough cash.
Insufficient balance.