Operators & expressions

Computer Science · Programming fundamentals

Question 1 of 10

0

    Evaluate the expression: 5 * 9 + 1

    Decimals (0.75 or 0,75), fractions (3/4) and mixed numbers (1 1/2) are accepted. Do not use thousands separators.

    How to type your answer
    • Fractions: 3/4. Mixed numbers: 1 1/2.
    • Decimals with a point or a comma: 0.75 or 0,75.
    • Negative numbers start with a minus: -3/4.
    • Percentages need the % sign: 75%.

    Stuck? Read the explanation

    Unlocks at a streak of 5 correct answers in a row.

    Print a free worksheet (PDF)

    Embed this practice on your site or class page

    Paste this HTML into your page. Students practise right there; it is free and needs no account.

    Operators & expressions explained

    An operator is a symbol that performs a calculation or comparison on values, such as + for addition or == for equality. An expression is any combination of values, variables and operators that the language evaluates to produce one result. Arithmetic operators handle sums: + adds, - subtracts, * multiplies, / divides and % gives the remainder after division.

    When an expression has several operators, precedence decides which one is applied first. Multiplication, division and remainder come before addition and subtraction, and brackets override everything. Operators of equal precedence are usually applied from left to right. So 2 + 3 * 4 is 14, not 20.

    Division needs care. In Python 3, 7 / 2 gives 3.5 but 7 // 2 gives 3, the floor division operator. In Java, dividing two whole numbers discards the fraction, so 7 / 2 gives 3.

    Worked example

    Evaluate the Python expression below.

    print(7 + 4 * 3 % 5)
    
    1. The operators * and % have equal precedence, so work from left to right.
    2. 4 * 3 = 12.
    3. 12 % 5 = 2, because 5 goes into 12 twice with 2 left over.
    4. 7 + 2 = 9.

    The program prints 9. Brackets make the intended order clear to a reader: 7 + ((4 * 3) % 5) means the same thing and also gives 9.

    What you will practise

    New numbers every time you practise. Levels: Easy, Medium, Hard. Each answer is followed by a worked explanation.

    Example questions

    • Easy

      Evaluate the expression: 3 * 5 + 1

    • Medium

      Evaluate the expression: 7 + 4 * 2

    • Hard

      Evaluate the expression: 25 - 6 - 6