Bird
Raised Fist0
Blockchain / Solidityprogramming~10 mins

Consensus mechanisms overview in Blockchain / Solidity - Interactive Code Practice

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

Complete the code to define the consensus mechanism used in Proof of Work.

Blockchain / Solidity
consensus = "[1]"
Drag options to blanks, or click blank then click option'
AByzantine Fault Tolerance
BProof of Stake
CDelegated Proof
DProof of Work
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing Proof of Work with Proof of Stake
Using Delegated Proof as the main consensus
2fill in blank
medium

Complete the code to check if the consensus mechanism is energy efficient.

Blockchain / Solidity
if consensus == "[1]":
    print("Energy efficient")
else:
    print("Not energy efficient")
Drag options to blanks, or click blank then click option'
AProof of Stake
BProof of Work
CProof of Authority
DProof of Capacity
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing Proof of Work as energy efficient
Confusing Proof of Authority with energy efficiency
3fill in blank
hard

Fix the error in the code to correctly identify the consensus mechanism that uses voting among nodes.

Blockchain / Solidity
if consensus == "[1]":
    print("Uses voting among nodes")
Drag options to blanks, or click blank then click option'
AProof of Work
BByzantine Fault Tolerance
CProof of Stake
DProof of Capacity
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing it with Proof of Stake
Choosing Proof of Work which is puzzle-based
4fill in blank
hard

Fill both blanks to create a dictionary mapping consensus mechanisms to their main characteristic.

Blockchain / Solidity
consensus_info = {
    "Proof of Work": "[1]",
    "Proof of Stake": "[2]"
}
Drag options to blanks, or click blank then click option'
AHigh energy consumption
BLow energy consumption
CFast finality
DDecentralized voting
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up energy consumption characteristics
Using voting or finality terms incorrectly
5fill in blank
hard

Fill both blanks to create a dictionary comprehension filtering consensus mechanisms with energy consumption less than 100.

Blockchain / Solidity
energy_use = {
    "PoW": 1000,
    "PoS": 10,
    "BFT": 50
}
low_energy = {k: v for k, v in energy_use.items() if v {BLANK_2}} {{BLANK_2}}
Drag options to blanks, or click blank then click option'
A:
B<
C100
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '<' in the condition
Forgetting the colon ':' in the comprehension

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

  1. Step 1: Understand the role of consensus

    Consensus mechanisms ensure all participants agree on the same data state.
  2. Step 2: Compare options

    Only To help multiple computers agree on a single version of data describes agreement on data; others describe unrelated functions.
  3. Final Answer:

    To help multiple computers agree on a single version of data -> Option C
  4. 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

  1. Step 1: Recall common consensus names

    Proof of Work is a widely used consensus mechanism name.
  2. Step 2: Check spelling and meaning

    Options B, C, and D are incorrect or made-up terms.
  3. Final Answer:

    Proof of Work -> Option B
  4. 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:
if node_vote > 50%:
    accept_block = True
else:
    accept_block = False
print(accept_block)

What will be printed if node_vote is 45?
medium
A. False
B. True
C. SyntaxError
D. None

Solution

  1. Step 1: Evaluate the condition with node_vote = 45

    45 is not greater than 50%, so condition is False.
  2. Step 2: Determine the value of accept_block

    Since condition is False, accept_block is set to False and printed.
  3. Final Answer:

    False -> Option A
  4. Quick Check:

    45 > 50%? No, so False [OK]
Hint: Check if vote is over 50% to accept block [OK]
Common Mistakes:
  • Assuming 45 is greater than 50%
  • Confusing True/False outputs
  • Expecting syntax errors in simple if-else
4. The following code tries to check if a block is accepted using Proof of Stake but has an error:
stake = 30
if stake >= 50
    block_accepted = True
else:
    block_accepted = False
print(block_accepted)

What is the error?
medium
A. Missing colon after if condition
B. Wrong variable name 'stake'
C. Indentation error on else
D. print statement syntax error

Solution

  1. Step 1: Check if statement syntax

    The if statement is missing a colon ':' at the end of the condition line.
  2. Step 2: Verify other parts

    Variable names, indentation, and print syntax are correct.
  3. Final Answer:

    Missing colon after if condition -> Option A
  4. 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

  1. Step 1: Understand the filtering condition

    Nodes must have at least 100 tokens, meaning tokens >= 100.
  2. 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.
  3. Final Answer:

    valid_nodes = [node for node in nodes if node.tokens >= 100] -> Option D
  4. 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 unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard