Complete the code to create a simple blockchain block structure with a timestamp.
block = {
'timestamp': [1],
'data': 'Sample data'
}The datetime.now() function provides the current timestamp for the block.
Complete the code to calculate the hash of a block's data using SHA-256.
import hashlib block_data = 'Transaction data' hash_result = hashlib.[1](block_data.encode()).hexdigest()
The sha256 function from hashlib is used to create a secure hash for blockchain data.
Fix the error in the code to add a new transaction to the blockchain list.
blockchain = []
new_transaction = {'sender': 'Alice', 'receiver': 'Bob', 'amount': 50}
blockchain.[1](new_transaction)add which is for sets.extend which expects an iterable.The append method adds a single item to the end of a list, which is correct for adding a transaction.
Fill both blanks to filter transactions with amount greater than 100 and create a dictionary with sender as key.
filtered = {tx['sender']: tx for tx in transactions if tx['amount'] [1] 100 and tx['receiver'] [2] 'Unknown'}The code filters transactions where amount is greater than 100 and receiver is not 'Unknown'.
Fill all three blanks to create a dictionary comprehension that maps block IDs to their data if the block is verified.
verified_blocks = {block[1]: block[2] for block in blocks if block[3] == True}The dictionary comprehension maps each block's ID to its data only if the block is verified.