diff --git a/main.py b/main.py index 06ec71c..a96838d 100644 --- a/main.py +++ b/main.py @@ -4,6 +4,7 @@ def get_tx_count(tx_list): Input: List of transaction IDs (strings) Output: Integer count """ + return len(tx_list) def filter_large_txids(tx_list, min_length): """ @@ -11,6 +12,7 @@ def filter_large_txids(tx_list, min_length): Input: List of txids (strings), minimum length (int) Output: Filtered list of strings """ + return [txid for txid in tx_list if len(txid) >= min_length] def process_txids(tx_list): """ @@ -19,6 +21,7 @@ def process_txids(tx_list): Input: List of txids (strings) Output: List of (int, string) tuples """ + return [(i, txid) for i, txid in enumerate(tx_list) if txid.startswith("tx")] def example_while_loop(limit): """ @@ -27,6 +30,14 @@ def example_while_loop(limit): Input: Integer limit Output: List of integers """ + result = [] + i = 0 + while i < limit: + if i == 5: + break + result.append(i) + i += 1 + return result def unpack_tuple(block_header): """ @@ -34,6 +45,8 @@ def unpack_tuple(block_header): Input: Tuple (int, str, int) Output: Unpacked tuple values """ + height, prev_hash, timestamp = block_header + return height, prev_hash, timestamp def dict_methods_example(block): """ @@ -42,6 +55,7 @@ def dict_methods_example(block): Input: Dict Output: Tuple of (list, list, list) """ + return list(block.keys()), list(block.values()), list(block.items()) def multiple_assignment(a, b): """ @@ -49,6 +63,8 @@ def multiple_assignment(a, b): Input: two integers Output: Tuple of two ints (swapped) """ + a, b = b, a + return a, b def set_example(addresses): """ @@ -57,6 +73,7 @@ def set_example(addresses): Input: List of strings Output: Set of strings """ + return set(addresses) class BitcoinTransaction: @@ -64,35 +81,42 @@ def __init__(self, txid, amount): """ TODO: Initialize transaction with txid (string) and amount (float). """ + self.txid = txid + self.amount = amount def __str__(self): """ TODO: Return string representation: "Tx {txid} of {amount} BTC" """ + return f"Tx {self.txid} of {self.amount} BTC" class Wallet: def __init__(self): """ TODO: Initialize an empty list to hold transactions. """ + self.transactions = [] def add_tx(self, tx): """ TODO: Add a BitcoinTransaction to the wallet's transaction list. """ + self.transactions.append(tx) def total_balance(self): """ TODO: Calculate and return the sum of amounts of all transactions. Output: Float """ - + return sum(tx.amount for tx in self.transactions) def txid_generator(tx_list): """ TODO: Yield each txid from the list one by one. Input: List of strings """ + for txid in tx_list: + yield txid def filter_txids_gen(tx_list, prefix="tx"): """ @@ -100,3 +124,6 @@ def filter_txids_gen(tx_list, prefix="tx"): Default prefix is 'tx'. Input: List of strings, prefix string """ + for txid in tx_list: + if txid.startswith(prefix): + yield txid \ No newline at end of file