Added more comments
This commit is contained in:
@@ -5,7 +5,7 @@ from __future__ import annotations
|
|||||||
from Card import Card
|
from Card import Card
|
||||||
|
|
||||||
def sum_cards_iter(cards: list[Card]) -> int:
|
def sum_cards_iter(cards: list[Card]) -> int:
|
||||||
total = 0
|
total = 0 #start total at 0
|
||||||
for card in cards:
|
for card in cards:
|
||||||
total = total + card
|
total = total + card
|
||||||
return total
|
return total
|
||||||
@@ -13,8 +13,10 @@ def sum_cards_iter(cards: list[Card]) -> int:
|
|||||||
|
|
||||||
def sum_cards_recursive(cards: list[Card]) -> int:
|
def sum_cards_recursive(cards: list[Card]) -> int:
|
||||||
if cards == []:
|
if cards == []:
|
||||||
|
#Base case
|
||||||
return 0
|
return 0
|
||||||
return cards[0] + sum_cards_recursive(cards[1:])
|
return cards[0] + sum_cards_recursive(cards[1:])
|
||||||
|
#Recursive case
|
||||||
#Added for project 2: Created a function to sum a list of Card objects using recursion.
|
#Added for project 2: Created a function to sum a list of Card objects using recursion.
|
||||||
|
|
||||||
def test_sum_cards():
|
def test_sum_cards():
|
||||||
|
|||||||
Reference in New Issue
Block a user