473,394 Members | 2,063 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 3896
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

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

Similar topics

0
by: sridev | last post by:
hi, I am new to VB.NET.I want to use grid control(not DataGrid) in VB.NET.I have added grid control in my project(By click project->AddReference->Com->microsoft Grid Control) Using this i...
6
by: Nirjhar Oberoi | last post by:
Hi, Can you add two numbers using a Single Variable? :-) If yes then show me the code!!! Regards Nirjhar
4
by: janice3 | last post by:
hi.I am a new member in this site. today my question is how to make a diamond shape using loops? the shape is like: * * * * * * * * * * * * * *...
4
by: GeekBoy | last post by:
I am reading a file of numbers using for loops. The numbers are in a grid as follows: 8 36 14 11 31 17 22 23 17 8 9 33 23 32 18 39 23 25 9 38 14 38 4 22 18 11 31 19 16 17 9 32 25 8 1 23
6
by: penny | last post by:
In this assignment we shall look at a possible representation of rational numbers in java using objects. The java language represents rational numbers using the same representation used for other...
3
by: aparna kulkarni | last post by:
i want to find out prime nos from 1 to 25 using do while loop.
1
by: lisles | last post by:
Can somebody tell me how to put values from a hidden field into a grid without using a database on click of add button.basically im entering some values into textboxes and i've to put these values...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.