473,385 Members | 1,492 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,385 software developers and data experts.

How to combine several related for loops into 2 for loops?

I begin to learn graphic in python.

The problem I'm encountering that is when I want to repeat an object (circle, rectangle, etc) I have to do with several repeated for loops (with little bit changing).

Assuming X is rectangle, O is circle. For each line I have to use a for loop. How can I combine them? I need the idea, not the source code.

XOXOXOXOXOXOXOXO
OXOXOXOXOXOXOXOX
XOXOXOXOXOXOXOXO
OXOXOXOXOXOXOXOX
XOXOXOXOXOXOXOXO
Sep 26 '07 #1
3 2284
ghostdog74
511 Expert 256MB
Expand|Select|Wrap|Line Numbers
  1. print "*" * 10 
  2.  
use it as example to create your pattern
Sep 26 '07 #2
bartonc
6,596 Expert 4TB
In the outer loop, keep track of the line number so you may test for odd/even line #:
Expand|Select|Wrap|Line Numbers
  1. >>> for i in range(10):
  2. ...     if i % 2:  #modulo test for odd/even
  3. ...         print i
  4. ...         
  5. 1
  6. 3
  7. 5
  8. 7
  9. 9
  10. >>> 
Sep 27 '07 #3
In the outer loop, keep track of the line number so you may test for odd/even line #:
Expand|Select|Wrap|Line Numbers
  1. >>> for i in range(10):
  2. ...     if i % 2:  #modulo test for odd/even
  3. ...         print i
  4. ...         
  5. 1
  6. 3
  7. 5
  8. 7
  9. 9
  10. >>> 
Thank you very much, now I got it
Sep 28 '07 #4

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

Similar topics

9
by: Steve Jorgensen | last post by:
Hi all, I'm working on the schema for a database that must represent data about stock & bond funds over time. My connundrum is that, for any of several dimension fields, including the fund name...
8
by: mark | last post by:
Access2000 How do I write a query that combines the CTC field from each record below into one record? I need to concatenate the CTC field with a separator, like below: ...
2
by: Henro V | last post by:
Can I integrate 3 existing forms (all based on the same query) integrate in one form by using Tab's? Thanx for thinking, Henro
3
by: msnews.microsoft.com | last post by:
Hi Does anybody know if XSLT can process several XML file at a time I have two xml document which stored in memory stream and wanna to combine it together under several rules. I am tring to...
1
by: luxmanpai | last post by:
Hello All, I have an performance issue, where a query which is executed at the client place which is retrieving 370 records is taking around 10 minutes, Where as the same query which is executed...
8
by: Mark Welch | last post by:
I am at a complete loss on how to do this. I am using Microsoft Access 2000, to implement a preliminary version of a reasonably modest relational database. I have two Access Tables (imported...
5
by: Rodjk #613 | last post by:
Hello, I am working with a database that is in use in several locations. The structure of the databases are identical, but the data is different. I am tasked with combining the data into one...
1
by: =?Utf-8?B?Sm9obg==?= | last post by:
Hi, I need to combine several bitmaps together to form a single bitmap. Can anyone show me some similar sample code? Thanks. AJ
1
by: bluereign | last post by:
Thank you for your assistance. I am a novice looking to JOIN and append or combine records from 2 current Tables into 2 new Tables named below. I have been able to JOIN Tables with the script...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.