Editor settings

General settings

Save settings

Learn to program with Python

Compound multiplication #

Compound multiplication is a shorthand way of multiplying 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: 10

Exercise #

  • Rewrite the code on line 3 to use *= to multiply the value of x and assign it back to the variable x
  • Value of x should be 100
Output will be displayed here