0
0
Blockchain / Solidityprogramming~10 mins

Why logic controls execution in Blockchain / Solidity - Test Your Understanding

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

Complete the code to check if a user has enough balance before sending tokens.

Blockchain / Solidity
if user_balance [1] amount_to_send:
    send_tokens()
Drag options to blanks, or click blank then click option'
A!=
B>=
C==
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' will allow sending tokens even if balance is less, causing errors.
Using '==' is too strict; user can have more than the amount.
2fill in blank
medium

Complete the code to execute a smart contract function only if the sender is the owner.

Blockchain / Solidity
if sender_address [1] contract_owner:
    execute_function()
Drag options to blanks, or click blank then click option'
A!=
B>
C==
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' would block the owner from executing the function.
Using '>' or '<' does not make sense for addresses.
3fill in blank
hard

Fix the error in the condition to prevent unauthorized access.

Blockchain / Solidity
if not (user_role [1] 'admin'):
    deny_access()
Drag options to blanks, or click blank then click option'
A==
B!=
Cin
Dnot in
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' inside with 'not' causes double negation and wrong logic.
Using 'in' or 'not in' is incorrect for string equality here.
4fill in blank
hard

Fill both blanks to create a condition that executes only if the transaction amount is positive and sender is verified.

Blockchain / Solidity
if transaction_amount [1] 0 and sender_verified [2] True:
    process_transaction()
Drag options to blanks, or click blank then click option'
A>
B<
C==
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' for amount allows zero or negative amounts.
Using '!=' for sender_verified allows unverified senders.
5fill in blank
hard

Complete the code to create a dictionary comprehension that maps user IDs to their balances only if balance is positive and user is active.

Blockchain / Solidity
user_balances = {user_id: balance for user_id, balance, active in users if balance [1] 0 and active}
Drag options to blanks, or click blank then click option'
A.upper()
C>
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Adding '.upper()' changes user_id to uppercase unnecessarily.
Using '==' instead of '>' allows zero balances.