Editor settings

General settings

Save settings

Learn to program with Python

Compound division #

Compound division is a shorthand way of dividing a variable by a given value and then assigning the result to the same variable. It uses the /= operator.

For example:

x = 5
x /= 2 # equivalent to x = x / 2
print(x)  # Output: 2.5

Exercise #

  • Rewrite the code on line 3 to use /= to divide the value of x and assign it back to the variable x
  • The value of x should be 50
Output will be displayed here