None, True, and False
Lesson 7 of 48 in Coddy's Python for JavaScript Developers course.
Represent an absent value and print Python boolean results with the correct spelling.
JavaScript
let chosen = null;
const available = true;
console.log(chosen);
console.log(available);Python
chosen = None
available = True
print(chosen)
print(available)What changes
The programs describe a missing choice and an available option, but their printed spellings differ: JavaScript prints null and true; Python prints None and True. Python also spells the other boolean False. These are values, not strings, so write them without quotes and preserve their capitalization. Comparisons produce booleans directly; you can print the result of count > 0 instead of constructing the words yourself. None represents absence when your application chooses that meaning. A real zero, an empty string, and an absent value can carry different information.
Common mistake
There is no general-purpose Python undefined value corresponding to all JavaScript uses. Reading an unassigned Python name raises NameError; it does not yield None. Likewise, writing lowercase true attempts to read a name rather than using the boolean literal. Do not use the string "None" as though it were the absence value.
Your task
Report availability and keep an absent report until a positive count is present. Later lessons will distinguish absence checks from general truthiness checks.
Challenge
BeginnerRead an integer seat count from 0 to 20. Print whether any seats remain, using Python's boolean spelling. On the next line print the count if it is positive, or None if it is zero. Initialize the reported value to None and replace it when seats remain.
Print only these lines, ending each with a newline. Keep the supplied input scaffold; it reads the stated values without prompts.
Your code goes in main.py. The locked driver.py starts your program and cannot be edited.
Try it yourself
# Starts the program in main.py. Edit main.py to solve the challenge.
from runpy import run_module
run_module("main", run_name="__main__")
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Python for JavaScript Developers
1From JavaScript to Python
Run Your First Python ProgramPrint, Comments, and StringsVariables Without let or constNumbers and ConversionBlocks Use IndentationRecap: Rewrite a Receipt4Iteration and Transformations
for Loops Iterate ValuesIndexes and Dict Iterationwhile, break, and continueComprehensions and SortingRecap: Build a Ranking2Values and Decisions
None, True, and FalseEquality and IdentityTruthiness and Short-CircuitBranches and ExpressionsRecap: Eligibility Rules3Collections and References
Lists Instead of ArraysTuples and UnpackingDictionaries and RecordsSets, Aliasing, and CopiesRecap: Clean an Inventory6Reliable Python Programs
Input and Output ContractsExceptions and ValidationModules and the Main GuardReading Type HintsRecap: Validate a Batch9Project: Order Processing
Create the Order ModelAdd Pricing PoliciesPractice on your own: Online Python compiler