Computer Science, asked by anindyaadhikari13, 28 days ago

In Python.

Task:
• Write one-liner códe to print the given series -
0 1 2 3 4 5 0 1 2 3 4 5....N terms.

Difficulty: Medium. ​

Answers

Answered by BrainlyProgrammer
36

QUESTION:-

Write one-liner códe to print the given series:-

  • 0 1 2 3 4 5 0 1 2 3 4 5....N terms.

Logic:-

  • Divide the natural number by 6

Answer:-

print(" ".join(str(i%6) for i in range(int(input("Enter N - ")))))

Dry Run:-

  • let accept n as 8
  • i will work from 0 to 7
  • now, when I is 0,
  • print(i%6) will print 0
  • when I is 1 then it will print 1
  • similarly when I will become 6 then 6%6=0 therefore, it will print 0
  • when I will become 7 then 7%6= 1

Note:-

  • % returns remainder.
Attachments:

Anonymous: Keep it up! :fb_wow:
TheMoonlìghtPhoenix: Awesome!
ExᴏᴛɪᴄExᴘʟᴏʀᴇƦ: Am jealous :meow_melt:
MisterIncredible: Splendid
Similar questions