New course! Every coder should learn Generative AI!
Try a free lesson+ 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
20 Answers
+ 11
Okie. I was worried if I had chronic eye disease. :>
+ 10
Can you point out to me as to how my output isn't correct.
+ 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('')
+ 8
@Ben Davis
He differs from other slackers in the sense that he actually attempted the task prior to seeking help from the community.
+ 3
Whom are you saying @Wright
+ 3
Check my answer, it gives the output as expected
+ 3
@Wright Look at the program I added for while loop
+ 3
Your output is correct Rei
+ 3
@Rei 😂😂😂 No you don't have such disease
+ 2
is there a way you can explain this so i understand how you did it
+ 2
why you all so keen to do Reginald's homework for him?
+ 1
at hatsy rei
+ 1
how would you use while loop to do same thing
+ 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")
+ 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)
+ 1
thank you guys
0
the output isn't correct
0
nevermind that
0
made a mistake