📖 Scenario: You are learning about blockchain technology. One important part is how computers agree on the data in the blockchain. This is called a consensus mechanism.Different blockchains use different consensus methods. You will create a simple program to list some common consensus mechanisms and their main features.
🎯 Goal: Build a Python dictionary that stores consensus mechanisms as keys and their descriptions as values. Then filter and display only those mechanisms that use energy-efficient methods.
📋 What You'll Learn
Create a dictionary called consensus_mechanisms with exact keys and values
Create a list called energy_efficient with exact consensus names
Use a dictionary comprehension to select only energy-efficient mechanisms
Print the filtered dictionary exactly as shown
💡 Why This Matters
🌍 Real World
Blockchain developers and enthusiasts often need to understand and compare different consensus mechanisms to choose the best one for their projects.
💼 Career
Knowledge of consensus mechanisms is important for blockchain engineers, developers, and architects working on secure and efficient distributed systems.
Progress0 / 4 steps
1
Create the consensus mechanisms dictionary
Create a dictionary called consensus_mechanisms with these exact entries: 'Proof of Work': 'Requires solving complex puzzles using high energy', 'Proof of Stake': 'Validators are chosen based on stake, uses less energy', 'Delegated Proof of Stake': 'Stakeholders vote for delegates to validate blocks', 'Practical Byzantine Fault Tolerance': 'Nodes agree through voting, energy efficient', 'Proof of Authority': 'Validators are pre-approved, low energy use'
Blockchain / Solidity
Hint
Use curly braces { } to create the dictionary with the exact keys and values.
2
Create the energy-efficient list
Create a list called energy_efficient containing these exact consensus mechanism names: 'Proof of Stake', 'Practical Byzantine Fault Tolerance', 'Proof of Authority'
Blockchain / Solidity
Hint
Use square brackets [ ] to create the list with the exact names as strings.
3
Filter energy-efficient consensus mechanisms
Use a dictionary comprehension to create a new dictionary called filtered_mechanisms that includes only the entries from consensus_mechanisms where the key is in the energy_efficient list.
Blockchain / Solidity
Hint
Use a dictionary comprehension with a for loop and an if condition to filter keys.
4
Print the filtered consensus mechanisms
Print the filtered_mechanisms dictionary exactly as it is.
Blockchain / Solidity
Hint
Use print(filtered_mechanisms) to display the filtered dictionary.
Practice
(1/5)
1. Which of the following best describes the main purpose of a consensus mechanism in blockchain?
easy
A. To store large files on the blockchain
B. To speed up internet connections
C. To help multiple computers agree on a single version of data
D. To encrypt messages between users
Solution
Step 1: Understand the role of consensus
Consensus mechanisms ensure all participants agree on the same data state.
Step 2: Compare options
Only To help multiple computers agree on a single version of data describes agreement on data; others describe unrelated functions.
Final Answer:
To help multiple computers agree on a single version of data -> Option C
Quick Check:
Consensus = Agreement [OK]
Hint: Consensus means agreement among many computers [OK]
Common Mistakes:
Confusing consensus with encryption
Thinking consensus speeds up internet
Mixing storage with agreement
2. Which syntax correctly names a popular consensus mechanism used in many blockchains?
easy
A. Proof of Walk
B. Proof of Work
C. Proof of Wait
D. Proof of Watch
Solution
Step 1: Recall common consensus names
Proof of Work is a widely used consensus mechanism name.
Step 2: Check spelling and meaning
Options B, C, and D are incorrect or made-up terms.
Final Answer:
Proof of Work -> Option B
Quick Check:
Correct name = Proof of Work [OK]
Hint: Remember the exact phrase: Proof of Work [OK]
Common Mistakes:
Misspelling 'Work' as 'Walk' or 'Wait'
Confusing similar-sounding words
Assuming all options are valid
3. Consider this simplified pseudocode for a blockchain consensus check:
The if statement is missing a colon ':' at the end of the condition line.
Step 2: Verify other parts
Variable names, indentation, and print syntax are correct.
Final Answer:
Missing colon after if condition -> Option A
Quick Check:
if statement needs ':' [OK]
Hint: Always put ':' after if conditions [OK]
Common Mistakes:
Ignoring missing colon errors
Thinking indentation is wrong
Assuming variable names cause error
5. You want to design a blockchain that uses Proof of Stake but only allows nodes with at least 100 tokens to vote. Which code snippet correctly filters nodes before voting?
hard
A. valid_nodes = [node for node in nodes if node.tokens < 100]
B. valid_nodes = [node for node in nodes if node.tokens > 1000]
C. valid_nodes = [node for node in nodes if node.tokens == 50]
D. valid_nodes = [node for node in nodes if node.tokens >= 100]
Solution
Step 1: Understand the filtering condition
Nodes must have at least 100 tokens, meaning tokens >= 100.
Step 2: Check each option's condition
valid_nodes = [node for node in nodes if node.tokens >= 100] uses >= 100, matching requirement; others do not.
Final Answer:
valid_nodes = [node for node in nodes if node.tokens >= 100] -> Option D
Quick Check:
At least 100 tokens = tokens >= 100 [OK]
Hint: Use >= 100 to include nodes with 100 tokens [OK]
Common Mistakes:
Using > 100 excludes nodes with exactly 100 tokens
Using < or == filters wrong nodes
Confusing token count conditions
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.