+ 1

[Solved]. Re: Multiples of 3 & 5 in python

[Solved] Why does this code return the numbers with the period? import numpy as np numbers = np.array([]) for i in range(1,100): if i % 3 == 0 and i % 5 == 0: numbers = np.append(numbers, i) print(numbers) Returns: [15. 30. 45. 60. 75. 90.] and not [15 30 45 60 75 90] like this code does: x = np.arange(1,100) print(x[(x%3==0)&(x%5==0)])

10th Apr 2022, 9:24 AM
Jan-Petter Fadum
Jan-Petter Fadum - avatar
4 Answers
+ 1
Numpy formats floating point numbers like that. 100. actually means 100.00 try print(numbers.astype(int)) https://code.sololearn.com/cRhhBdEElSkH/?ref=app
10th Apr 2022, 9:34 AM
Abhishek Tandon
Abhishek Tandon - avatar
0
>Numpy formats numbers like that. 100. actually means 100.00 But why does not the second (solution) code return it like that?
10th Apr 2022, 9:38 AM
Jan-Petter Fadum
Jan-Petter Fadum - avatar
0
I edited the answer. Please read again
10th Apr 2022, 9:39 AM
Abhishek Tandon
Abhishek Tandon - avatar
0
Fantastic! Thanks a lot! :-)
10th Apr 2022, 9:41 AM
Jan-Petter Fadum
Jan-Petter Fadum - avatar