PNL Learn

Python Logic and Numbers

Make decisions with booleans and if, and do real math with numbers.

Teach your programs to calculate and to decide. You will use every arithmetic operator, including floor division and modulo with negative numbers, convert between int and float, get operator precedence right (including how ** groups), and keep float noise out of money. Then you will compare values, count true answers, branch with if, elif and else, tell separate ifs from a chain, and pick values with a conditional expression. You will combine conditions with and, or and not, learn what Python treats as true or false, test for None the right way, and finish by writing real rule-based functions: guard clauses in priority order, shipping tiers, leap years, password checks, ticket pricing and a FizzBuzz report.

BeginnerPython5 lessons68 exercisesAbout 5 h
Create a free account

What you will learn

  • Arithmetic operators
  • Floor division and modulo
  • Operator precedence
  • int and float conversion
  • Booleans
  • Comparisons
  • if / elif / else
  • Conditional expressions
  • Logical operators
  • Truthiness

Lessons

  1. 1

    Numbers and Operators

    Divide three ways, take remainders, convert between int and float, raise powers in the right order, round results and update values in place.

    14 exercises

  2. 2

    Booleans and Comparisons

    Ask yes-or-no questions with comparison operators, count answers as numbers, compare floats and text safely, and check ranges with chained comparisons.

    14 exercises

  3. 3

    if, elif and else

    Run different code depending on conditions, order an elif chain, tell separate ifs from a chain, nest decisions, cover every path, and pick a value with a conditional expression.

    15 exercises

  4. 4

    and, or, not and Truthiness

    Combine conditions in the right order, rely on short-circuiting, learn what Python treats as true or false, test for None the right way, and avoid the or-default and plain-English traps.

    15 exercises

  5. 5

    Putting It Together

    Turn real business rules into functions: guard clauses in priority order, password checks, ticket prices, rounding up, shipping tiers, leap years and a FizzBuzz report.

    10 exercises

How you practice

You practice in the browser and every exercise gives you feedback right away. This course uses these formats:

  • Code exercise: 25
  • Predict the output: 12
  • Fix the bug: 9
  • Type the answer: 7
  • Fill in the blank: 6
  • Match the pairs: 2
  • Select all that apply: 2
  • Reorder lines: 2
  • Multiple choice: 2
  • Spot the bug: 1

Aligned to

PCEP-30-02Python InstituteSource
  • Computer Programming and Python Fundamentals
    • 1.4Choose operators and data types adequate to the problem
  • Control Flow - Conditional Blocks and Loops
    • 2.1Make decisions and branch the flow with the if instruction
CS2023ACM / IEEE-CS / AAAISource
  • Software Development Fundamentals
    • SDF-FundamentalsFundamental Programming Concepts and Practices

Proto Node Labs is not affiliated with or endorsed by Python Institute and ACM / IEEE-CS / AAAI. Exam names are trademarks of their owners.