Δημοσιεύτηκε: 12 Ιουν 2014, 13:35
από midkin
Επανέρχομαι στο θέμα μετά από λίγες μέρες και λίγο πιο διαβασμένος (μετά την επανάληψη)! Οπότε το πρόγραμμα τρέχει κάπως έτσι;
Κώδικας: Επιλογή όλων
def total(initial=5, *numbers, **keywords):
count = initial  #count = initial = 5
for number in numbers:
count += number # count = count + number = ...
for key in keywords:
count += keywords[key]  #count = count + keywords[key] = ...
return count # ok!
print(total(10, 1, 2, 3, vegetables=50, fruits=100))


# - - - - - - - - - - Running program - - - - - - - - - -
# initial = 10,  numbers = (1,2,3),  keywords = {vegetables : 50, fruits : 100}
# so, count = initial = 10
# ----- running the for loop: -----
#count = 10 + 1
#count = 11 + 2
#count = 13 + 3
# ----- running the 2nd for loop: -----
#count = 16 + 50
#count = 66 + 100
# ----- executing the return: -----
#166


Σωστά; :geek: