Python Challenge 1

+2 Robert Summers · September 13, 2014
So I was just watching Bucky's 10th Python Programming Tutorial and have attempted to try Bucky's Challenge. I could not work this one out. He asked for a loop to 100 and print out every multiple of 4. I'm stuck, this is the only bit I have worked out.

Help and answers would be greatly appreciated. 

x = 0

for x in range(100):
    if (x % 4):{

Thank you.

Post a Reply


Oldest  Newest  Rating
0 Brock Cryoston · October 15, 2014
This is the most compact way of doing it, producing the same result with a different method.
It just basically counts up by the increments of 4.
0 Ethan Hann · October 14, 2014
I know they do the same thing, however it may be easier to read if you write it with a continue statement. For each number in the range it will test if that number is divisible by 4: if it is print it out on the screen; if it isn't continue to the next number in the range. It just makes the code a little easier to understand IMO.
0 Nate Penner · October 4, 2014
The else: continue doesn't serve any purpose, the loop will continue anyways
0 Nate Penner · October 4, 2014

for x in range(1, 101):
    if x % 4 is 0:
0 Ethan Hann · September 20, 2014
You could also use an if-else-continue statement :)

#This program will print out the multiples of 4 from 0 to 100

for n in range(101):
    if n % 4 == 0:
0 Robert Summers · September 17, 2014
Thanks for the help dude :):):):):)
+1 Nathanael Potter · September 13, 2014
You need to say that if x is 0 (After doing x%4) then print x

for x in range (101):
if x%4 is 0:
  • 1



This section is all about snakes! Just kidding.

Bucky Roberts Administrator