469,357 Members | 1,921 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,357 developers. It's quick & easy.

printing a grid of numbers using for loops

how do I print a grid of numbers ranging from -2 to 41 in 6 rows with 7 numbers in a row using the for loop
Mar 20 '15 #1
1 3247
bvdet
2,851 Expert Mod 2GB
Have you tried to write the code yourself, or are you looking for someone to write it for you? You could start by defining the numbers for printing.
Expand|Select|Wrap|Line Numbers
  1. numbers_to_print = range(-2,42)
As a hint, you can use the modulo operator (%), built-in function enumerate, and extended slicing to achieve your goal.

Should it look like this?
Expand|Select|Wrap|Line Numbers
  1. >>> -2 -1 0 1 2 3 4
  2. 5 6 7 8 9 10 11
  3. 12 13 14 15 16 17 18
  4. 19 20 21 22 23 24 25
  5. 26 27 28 29 30 31 32
  6. 33 34 35 36 37 38 39
  7. >>>
Mar 20 '15 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by sridev | last post: by
6 posts views Thread by Nirjhar Oberoi | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.