GH avatar Bite 254. Global vs local variables

This Bite is to illustrate scoping. You will sum numbers while keeping track of number of hundreds in a global variable called num_hundreds.

To illustrate this see this REPL output:

>>> from scoping import sum_numbers, num_hundreds
>>> num_hundreds
>>> sum_numbers([10, 20, 70])
>>> from scoping import num_hundreds
>>> num_hundreds
>>> sum_numbers([10, 120, 180])
>>> from scoping import num_hundreds
>>> num_hundreds

We planned to also illustrate nonlocal, but we will do that in a separate Bite ... Good luck and keep calm and code in Python!

Login and get coding
go back Beginner level
Bitecoin 2X

101 out of 103 users completed this Bite.
Will you be Pythonista #102 to crack this Bite?
Resolution time: ~20 min. (avg. submissions of 5-240 min.)
Pythonistas rate this Bite 1.5 on a 1-10 difficulty scale.
» You can do it! 😌

We use Python 3.8