0
newarray = [x + 0.5 for x in range(1, 10)]

this code will give me following result:

newarray
[1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5]

Instead of adding 0.5 with x I want to increase my x by 0.5 for each 1 increment of x. The output suppose to be

newarray=[0.5,1,1.5,2,2.5......5.5].

Keep in mind that my range must be fix in 1 to 10. What can be better approach to make that?

1 Answer 1

1
[0.5 * x for x in range(1, 12)]

Will do the thing, I'm afraid generating that array with range(1, 10) is impossible

Sign up to request clarification or add additional context in comments.

5 Comments

Maybe you should write the desired result completely @TanvirHossain
result=[0.5,1,1.5,2,2.5,3,3.5,4,4.5,5,5.5]...it should not start from 0.
Look, range(1, 10) will give you a list of 9 values, and you want a list with 11 ones. @TanvirHossain
if I keep my range (0,10) is it possible to start my array from 0.5?
0, 10? Yes, [(x + 1) * 0.5 for x in range(0, 10)]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.