Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
291 views
in Technique[技术] by (71.8m points)

python - Multiplying the current value of a variable

Write a statement that assigns cell_count with cell_count multiplied by 10. * performs multiplication. If the input is 10, the output should be: 100

cell_count = int(input())

''' Your solution goes here '''

print(cell_count)

I am putting cell_count * 10 and its not the correct answer, can someone help me.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You doing cell_count * 10 is the correct calculation, but since you are not assigning it back to the variable cell_count, it remains the same as earlier and that's why your answer is showing incorrect.

To understand, if we say a = 2 and then a+1 is 3, but a is still 2, to make a = 3, you will have to do a a = a+1.

So there are two approaches:

The simplest is

cell_count = cell_count * 10

Another more efficient way is cell_count *= 10, *= is a special character in python which multiplies and assigns to itself in one single operation.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...