Multiplying the current value of a variable

Question:

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.

Asked By: Sunnymuffins721

||

Answers:

It can be

cell_count *= 10 

or

cell_count = cell_count*10 
Answered By: matebende

I think you forgot to assign value back to the variable, so you can use the output. You can try this:

cell_count = int(input())

cell_count *= 10

or this:

cell_count = int(input())

cell_count = cell_count * 10 
Answered By: AhmedH2O

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.

Answered By: srishtigarg

for posterity:


cell_count = int(input()) <– line 1 which can not be edited

cell_count = cell_count * int(10) <— my line

print(cell_count) <—- line that can not be edited


is the answer I input and was accepted.

Answered By: jmorg38
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.