abobaker09

challenge number3

Sep 12th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.33 KB | None | 0 0
  1. #تحدي رقم ٣
  2. #اكتب دالة تجمع عناصر قائمة
  3. #حل اول بواسطة ريكريجن
  4. def y(a):
  5.     if a[0] in a:
  6.         return a[0]
  7.     else:
  8.         return a[0]+y(a[1:])
  9. print(y([1,2,3,4]))
  10. #حل ثاني
  11. def y(a) :
  12.     u=0
  13.     for x in a:
  14.         u+=x
  15.         return u
  16. print(y([1,2,3,4]))
Advertisement
Add Comment
Please, Sign In to add comment