Explorar o código

Merge pull request #41 from dbojan/patch-5

change function_varargs.py so it is more easily understood to beginners
Swaroop C H %!s(int64=9) %!d(string=hai) anos
pai
achega
1288464b66
Modificáronse 1 ficheiros con 11 adicións e 8 borrados
  1. 11 8
      programs/function_varargs.py

+ 11 - 8
programs/function_varargs.py

@@ -1,9 +1,12 @@
-def total(initial=5, *numbers, **keywords):
-    count = initial
-    for number in numbers:
-        count += number
-    for key in keywords:
-        count += keywords[key]
-    return count
+def total(a=5, *numbers, **phonebook):
+    print('a', a)
+    
+    #iterate through all the items in tuple
+    for single_item in numbers:
+        print('single_item', single_item)
+        
+    #iterate through all the items in dictionary    
+    for first_part, second_part in phonebook.items():
+        print(first_part,second_part)
 
-print(total(10, 1, 2, 3, vegetables=50, fruits=100))
+print(total(10,1,2,3,Jack=1123,John=2231,Inge=1560))