Visual Algorithms Meet Motion: mBlock Practice for Yokohama Learners
Yokohama families gain from visual robotics that stays optional on hardware. Enquire WhatsApp +92 322 4217059. No invented Yokohama studio.
mBlock robot building and sensor coding for Yokohama lets students write visual algorithms that control motor drives, line-following ideas and light indicators—on screen first, optional hardware later.

Video coming soon
Lesson notes and Q&A below are available now. The video will appear here when published.
In Python programming, functions are reusable blocks of code created to execute specific instructions whenever called. When writing functions, programs inevitably declare and manipulate variables.
However, where a variable is created determines where it can be seen and used across the rest of the application. This boundary of visibility and accessibility is known as variable scope.
In Python, variable scope is divided into two primary categories:
While Python technically allows functions to read global variables directly, relying on global variables across multiple functions is considered poor programming practice.
The Recommended Approach:
return keyword and capture it into a global-scope variable.In this code, a function named show() defines a local variable x with the value 5 and prints it:
# Defining the function with a local variable x
def show():
x = 5
print(x)
Running this definition creates the function blueprint in memory without producing immediate screen output.
Next, define a global variable with the same name x at the program level, set its value to 10, and execute show():
# Defining a global variable at program level
x = 10
# Calling the function
show()
Output:
5
How Python Evaluates This:
x: a global x equal to 10 and a local x inside show() equal to 5.show() executes, Python gives precedence (priority) to the local variable over the global variable.x and prints 5 rather than the outer value 10.If you execute a print(x) statement outside the function in the global scope:
# Printing x in the global program scope
print(x)
Output:
10
How Python Evaluates This:
print(x) statement sits outside the function, the local variable inside show() (x = 5) is completely inaccessible.x, printing 10.return that value so it can be captured in a variable at the global level.A local variable is declared inside a function's body and is accessible only within that specific function. It cannot be viewed or accessed from the outside program. A global variable is declared at the main program level outside of any function and is accessible throughout the program and across functions.
When a function contains a local variable with the same name as a global variable (such as a local x = 5 and a global x = 10), the local variable takes precedence inside the function. When called, the function will access and print its local value (5). Outside the function, however, the local variable is inaccessible, and referencing that variable name accesses the global value (10).
Relying on global variables makes programs difficult to maintain because when multiple functions interact with the same global data, it becomes hard to track which function modified the variable when bugs occur. Good programming practice recommends using local variables, passing needed data into functions as input parameters, and using the return statement to send computed results back to the global scope to be stored in variables.
mBlock Coding Fast Track for Beginners on Udemy.
Disclosure: This page contains affiliate links. We may earn from qualifying purchases at no extra cost to you. Links are intended for parents and educators, not as marketing directed at young children.
Yokohama families gain from visual robotics that stays optional on hardware. Enquire WhatsApp +92 322 4217059. No invented Yokohama studio.
mBlock combines Scratch-style visual coding with real-time hardware execution. Students in Yokohama write block algorithms that control physical mBot motor drives, line-following sensors, and RGB light indicators in real time.
Yes! We utilize interactive virtual robotics simulators during online live sessions, enabling students to program and test robot movements on screen prior to purchasing physical hardware.
Click the WhatsApp button on this page to connect with our mentor team and secure a free live trial session this week.