Beatty sequence | Python3 implementation of the above approach ; Function to print the first N terms of the Beatty sequence ; Driver code
import math NEW_LINE def BeattySequence ( n ) : NEW_LINE INDENT for i in range ( 1 , n + 1 ) : NEW_LINE INDENT ans = math . floor ( i * math . sqrt ( 2 ) ) NEW_LINE print ( ans , end = ' , ▁ ' ) NEW_LINE DEDENT DEDENT n = 5 NEW_LINE BeattySequence ( n ) NEW_LINE