diff --git a/main.py b/main.py index 06ec71c..bef9842 100644 --- a/main.py +++ b/main.py @@ -4,6 +4,8 @@ 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 +13,8 @@ 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 +23,13 @@ def process_txids(tx_list): Input: List of txids (strings) Output: List of (int, string) tuples """ + result = [] + for i, txid in enumerate(tx_list): + if not txid.startswith('tx'): + continue + result.append((i, txid)) + return result + def example_while_loop(limit): """ @@ -27,6 +38,15 @@ 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 +54,9 @@ 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 +65,8 @@ 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 +74,9 @@ 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 +85,7 @@ def set_example(addresses): Input: List of strings Output: Set of strings """ + return set(addresses) class BitcoinTransaction: @@ -64,39 +93,55 @@ 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 """ +def txid_generator(tx_list): + + for txid in tx_list: + yield txid + -def filter_txids_gen(tx_list, prefix="tx"): """ TODO: Yield txids from list that start with given prefix. Default prefix is 'tx'. Input: List of strings, prefix string """ +def filter_txids_gen(tx_list, prefix="tx"): + + for txid in tx_list: + if txid.startswith(prefix): + yield txid