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.
Answers:
It can be
cell_count *= 10
or
cell_count = cell_count*10
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
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.
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.
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.
It can be
cell_count *= 10
or
cell_count = cell_count*10
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
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.
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.