+ 1

python trying to make a counter variable to make 6 rows and 6 columns

Write a program that uses a for loop and the range function to process all integers from 999 down to zero. Code in the loop should print multiples of 40 on one line separated by spaces, but with only six on one line. See Required Output. Use a counter to determine when six multiples have been printed. Required Output 960 920 880 840 800 760 720 680 640 600 560 520 480 440 400 360 320 280 240 200 160 120 80 40 This is what i have so far counter = 0 for num in range (1000, 0, -40): if counter == counter*6: counter+=1 print("{:6d}".format(num)) else: counter=0 Output: 1000 960 920 880 840 800 760 720 680 640 600 560 520 480 440 400 360 320 280 240 200 160 120 80 40

4th Sep 2017, 8:27 AM
Reginald Wright
Reginald Wright  - avatar
20 ответов
4th Sep 2017, 8:53 AM
Kartikey Sahu
Kartikey Sahu - avatar
+ 11
Okie. I was worried if I had chronic eye disease. :>
4th Sep 2017, 9:34 AM
Hatsy Rei
Hatsy Rei - avatar
+ 10
Can you point out to me as to how my output isn't correct.
4th Sep 2017, 9:31 AM
Hatsy Rei
Hatsy Rei - avatar
+ 8
#I suppose we have to follow all the instructions strictly, so this is my attempt. If not, there should be easier ways. counter = 0 for num in range(999, 0, -1): if num%40 == 0: print(num, end = ' ') counter += 1 if counter%6 == 0: print('')
4th Sep 2017, 8:47 AM
Hatsy Rei
Hatsy Rei - avatar
+ 8
@Ben Davis He differs from other slackers in the sense that he actually attempted the task prior to seeking help from the community.
4th Sep 2017, 9:55 AM
Hatsy Rei
Hatsy Rei - avatar
+ 3
Whom are you saying @Wright
4th Sep 2017, 8:57 AM
Kartikey Sahu
Kartikey Sahu - avatar
+ 3
Check my answer, it gives the output as expected
4th Sep 2017, 9:06 AM
Kartikey Sahu
Kartikey Sahu - avatar
+ 3
@Wright Look at the program I added for while loop
4th Sep 2017, 9:10 AM
Kartikey Sahu
Kartikey Sahu - avatar
+ 3
Your output is correct Rei
4th Sep 2017, 9:33 AM
Kartikey Sahu
Kartikey Sahu - avatar
+ 3
@Rei 😂😂😂 No you don't have such disease
4th Sep 2017, 9:36 AM
Kartikey Sahu
Kartikey Sahu - avatar
+ 2
is there a way you can explain this so i understand how you did it
4th Sep 2017, 8:54 AM
Reginald Wright
Reginald Wright  - avatar
+ 2
why you all so keen to do Reginald's homework for him?
4th Sep 2017, 9:48 AM
Ben-Davis
Ben-Davis - avatar
+ 1
at hatsy rei
4th Sep 2017, 9:01 AM
Reginald Wright
Reginald Wright  - avatar
+ 1
how would you use while loop to do same thing
4th Sep 2017, 9:07 AM
Reginald Wright
Reginald Wright  - avatar
+ 1
@reginald I think your code was complete conceptually and almost the same as the answers generously offered by @Hatsy and @Kartikey, it's just they had an extra formatting trick you may not have known about .... eg print("stuff" end="spaces NOT new line")
4th Sep 2017, 9:57 AM
Ben-Davis
Ben-Davis - avatar
+ 1
https://code.sololearn.com/c47tk7HgKWAT/?ref=app just to make the code 2 lines only... not necessarily better ... just shorter ...and now I made all columns right justified (I couldn't stop myself)
4th Sep 2017, 10:39 AM
Ben-Davis
Ben-Davis - avatar
+ 1
thank you guys
5th Sep 2017, 12:33 AM
Reginald Wright
Reginald Wright  - avatar
0
the output isn't correct
4th Sep 2017, 8:53 AM
Reginald Wright
Reginald Wright  - avatar
0
nevermind that
4th Sep 2017, 8:53 AM
Reginald Wright
Reginald Wright  - avatar
0
made a mistake
4th Sep 2017, 9:38 AM
Reginald Wright
Reginald Wright  - avatar