Bucky's divide by 4 challenge

 Kabir Knight · May 25, 2015 Backstory: So, I was teaching my young nephew Python, as always referred him to Bucky's Python 3.4 tutorials which he posted last year (I think). So in one of the first few videos when he introduced loops, he challenged (assigned homework - his words, not mine) to leaner to write a code to print all numbers divisible 4 between 1 and 100. My nephew had very limited exposure to computers, let alone programming. He paused the video and wrote out the code (given below) in 10 minutes - all from lessons in less than 10 videos.I just want to thank Bucky  and his buddies for the wonderful and entertaining sessions. Good job and keep it up!!!Here's the code (Keep in mind - the first code by a 14 year old without any programming experience and less than 30 minutes of Bucky's tutorials)``divFour = []ndivFour = []for x in range(1,101): if x%4: ndivFour.append(x) else: divFour.append(x)print('Numbers Divisible by 4 between 1 and 100 are: ')for y in divFour: print(y)print("Here's a list of numbers not divisible by 4 between 1 and 100: ")for z in ndivFour: print(z)``I am not exactly sure if anyone else posted a similar code, but I was impressed.NOTE: The original "assignment" by Bucky was just to print all multiples of 4 between 1 and 100. There was no mention of use of arrays or printing other numbers.

Replies

- page 2

 Kabir Knight · May 30, 2015 Thank you for the responses. What I wanted to portray in this thread was that the 14 year old wrote a simple program with some additional lines implementing all that he learned in 8 videos. The point was not about simplicity but what he implemented. Nicholas Njenga · May 29, 2015 Simplified solution for n in range(101):if n%4==0:print(n, "is divisible by 4") continue I'll try and solve ur problem Patel Pavel Dimi · May 29, 2015 ``first_number = 4for i in range(1, 26): print(first_number*i)`` Dan Pena · May 28, 2015 Here's all I did:for n in range(1,101):    if n %4 is 0:        print (n)Yes I'm new to programming! Dol Lod · May 26, 2015 Your nephew's solution was valid, but Nicholas had a simpler solution. Great job if he's new to programming.Here is a slightly more advanced challenge of the same difficulty:1) Given a list of numbers, determine if numbers in a certain range are divisible by all those numbers. Nicholas Njenga · May 26, 2015 I just did thisfor n in range(101) :if n%4 ==0:print(n, "is divisible by 4")else:print(n,"is not divisible by 4")
• 1
• 2

Python

126,781 followers