Python Augmented arithmetic in for loop range

Viewed 38

I've got assignment to multiply 256x2x2x2 by using loop in range using this code.

jawaban_5 = 256
for ... in range(...): # Use Range
    jawaban_5 ...= ... # Use Augmented Arithmetic 
    
print(jawaban_5)

with the result of 2048.

But everytime what i did is 0 using this code

jawaban_5 = 256
for x in range(2): # Tentukan range yang sesuai
    jawaban_5 *= x # Gunakan Augmented Arithmetic Assignments
    
print(jawaban_5)

Can someone explain to me how to improve it?

1 Answers

range starts at 0, so it makes the result 0 in the first step.

You need to use the number 2 as multiplier, not the number from the range. Also, your range needs to be 3 as you multiply by 2 3 times

jawaban_5 = 256
for x in range(3): # 3 loops
    jawaban_5 *= 2 
    
print(jawaban_5)

output: 2048

Related