Consider a simple Python simulation of a sidechain token transfer. What will be printed after running the code?
class Sidechain: def __init__(self): self.balances = {"main": 1000, "side": 0} def lock_tokens(self, amount): if self.balances["main"] >= amount: self.balances["main"] -= amount self.balances["side"] += amount print(f"Locked {amount} tokens to sidechain") else: print("Insufficient tokens on main chain") def unlock_tokens(self, amount): if self.balances["side"] >= amount: self.balances["side"] -= amount self.balances["main"] += amount print(f"Unlocked {amount} tokens to main chain") else: print("Insufficient tokens on sidechain") sc = Sidechain() sc.lock_tokens(300) sc.unlock_tokens(100) print(sc.balances)
Think about how tokens move between main and sidechain balances after locking and unlocking.
Initially, 1000 tokens are on the main chain. Locking 300 moves 300 tokens to the sidechain, reducing main to 700 and side to 300. Then unlocking 100 moves 100 tokens back to main, so main becomes 800 and side 200.
Choose the option that correctly explains why sidechains are used in blockchain technology.
Think about how sidechains help with scalability and flexibility.
Sidechains enable assets to move between chains, allowing new features and scalability improvements without altering the main blockchain.
The following Python code simulates locking assets to a sidechain. It raises an error when run. What is the cause?
class Sidechain: def __init__(self): self.balances = {"main": 500, "side": 0} def lock(self, amount): if self.balances["main"] >= amount: self.balances["main"] -= amount self.balances["side"] += amount else: print("Not enough tokens") sc = Sidechain() sc.lock(600)
Check the syntax of the if-else block carefully.
The else statement is missing a colon at the end, causing a SyntaxError.
Choose the code snippet that correctly defines a method to withdraw tokens from a sidechain back to the main chain.
Look for correct syntax and correct operators.
Option D uses correct syntax with colon after if, correct comparison operator, and correct += operator. Others have syntax errors or wrong operators.
Given the following sequence of operations on a sidechain, how many tokens remain on the sidechain?
sc = Sidechain() sc.lock_tokens(400) sc.unlock_tokens(150) sc.lock_tokens(100) sc.unlock_tokens(200) print(sc.balances)
class Sidechain: def __init__(self): self.balances = {"main": 1000, "side": 0} def lock_tokens(self, amount): if self.balances["main"] >= amount: self.balances["main"] -= amount self.balances["side"] += amount def unlock_tokens(self, amount): if self.balances["side"] >= amount: self.balances["side"] -= amount self.balances["main"] += amount
Track each lock and unlock step carefully to update balances.
Start with main=1000, side=0. Lock 400: main=600, side=400. Unlock 150: main=750, side=250. Lock 100: main=650, side=350. Unlock 200: main=850, side=150. Final side balance is 150.