Consider a blockchain ledger represented as a list of blocks. Each block contains a transaction amount. What will be the total balance after adding these blocks?
ledger = [100, -20, 50] total_balance = sum(ledger) print(total_balance)
Sum all the amounts in the ledger list.
The ledger has transactions 100, -20, and 50. Adding them gives 130.
In a distributed ledger system, what is the key property that guarantees all nodes share the same data?
Think about how nodes agree on the ledger state.
Consensus is the process that ensures all nodes agree on the ledger's current state.
Analyze the code below that validates a block's hash. What error will it raise when run?
def validate_block(block): if block['hash'] == block['prev_hash']: return True else: return False block = {'hash': 'abc123', 'prev_hash': 'def456'} print(validate_block(block))
Check the syntax of the if-else statement.
The else statement is missing a colon, causing a SyntaxError.
Choose the code snippet that correctly creates a block dictionary with keys 'index', 'timestamp', and 'data'.
Remember the syntax for dictionary key-value pairs in Python.
Option A uses correct colon separators and commas between items.
Given the initial blockchain and a function to add blocks, what is the length of the blockchain after adding two new blocks?
blockchain = [{'index': 0, 'data': 'Genesis'}]
def add_block(chain, data):
index = chain[-1]['index'] + 1
chain.append({'index': index, 'data': data})
add_block(blockchain, 'Tx1')
add_block(blockchain, 'Tx2')
print(len(blockchain))Count the original block plus the added blocks.
The blockchain starts with 1 block and adds 2 more, total 3 blocks.