0
0
Blockchain / Solidityprogramming~10 mins

Blockchain use cases beyond crypto - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a simple blockchain block structure with a timestamp.

Blockchain / Solidity
block = {
    'timestamp': [1],
    'data': 'Sample data'
}
Drag options to blanks, or click blank then click option'
Atime.time()
Bdatetime.now()
Crandom.randint(1, 100)
D'2024-01-01'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a fixed string instead of a dynamic timestamp.
Using a random number instead of a timestamp.
2fill in blank
medium

Complete the code to calculate the hash of a block's data using SHA-256.

Blockchain / Solidity
import hashlib

block_data = 'Transaction data'
hash_result = hashlib.[1](block_data.encode()).hexdigest()
Drag options to blanks, or click blank then click option'
Amd5
Bsha512
Csha1
Dsha256
Attempts:
3 left
💡 Hint
Common Mistakes
Using weaker hash functions like MD5 or SHA1.
Using a hash function not supported by hashlib.
3fill in blank
hard

Fix the error in the code to add a new transaction to the blockchain list.

Blockchain / Solidity
blockchain = []
new_transaction = {'sender': 'Alice', 'receiver': 'Bob', 'amount': 50}
blockchain.[1](new_transaction)
Drag options to blanks, or click blank then click option'
Aappend
Badd
Cextend
Dinsert
Attempts:
3 left
💡 Hint
Common Mistakes
Using add which is for sets.
Using extend which expects an iterable.
4fill in blank
hard

Fill both blanks to filter transactions with amount greater than 100 and create a dictionary with sender as key.

Blockchain / Solidity
filtered = {tx['sender']: tx for tx in transactions if tx['amount'] [1] 100 and tx['receiver'] [2] 'Unknown'}
Drag options to blanks, or click blank then click option'
A>
B<
C!=
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using less than instead of greater than.
Using equality instead of inequality for receiver check.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps block IDs to their data if the block is verified.

Blockchain / Solidity
verified_blocks = {block[1]: block[2] for block in blocks if block[3] == True}
Drag options to blanks, or click blank then click option'
A['id']
B['data']
C['verified']
D['timestamp']
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong keys for dictionary mapping.
Checking the wrong field for verification.