By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,686 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

printing a grid of numbers using for loops

P: 1
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
Share this Question
Share on Google+
1 Reply


bvdet
Expert Mod 2.5K+
P: 2,851
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.