473,503 Members | 2,150 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

new in programing

i want to now how to do this in python
this is java
for(int i=1 ; i<=lim ; i++){

for(int j=i+1; j<=lim+1; j++){

for(int k =j+1; k<=lim+2;k++){

for(int l=k+1 ; l<=lim+3;l++){

for(int m=l+1 ; m<=lim+4;m++){

for(int o=m+1 ; o<=lim+5;o++){

Dec 9 '05 #1
7 1433
Efrain Marrero wrote:
i want to now how to do this in python
this is java
for(int i=1 ; i<=lim ; i++){

for(int j=i+1; j<=lim+1; j++){

for(int k =j+1; k<=lim+2;k++){

for(int l=k+1 ; l<=lim+3;l++){

for(int m=l+1 ; m<=lim+4;m++){

for(int o=m+1 ; o<=lim+5;o++){


That code wouldn't run on a JVM, do you have the rest? Or are we to
assume these loops do nothing and just close all the braces?

Dec 9 '05 #2
Python iterates over "things" (objects), of which integer numbers are
just one possible choice. The range built-in command produces ranges of
integers which are useful for tasks such as this.

lim = 3

for i in range( 1, lim+1 ):
for j in range( i+1, lim+2):
for k in range( j+1, lim+3):
for l in range( k+1, lim+4):
for m in range( l+1, lim+5):
for n in range( m+1, lim+6):
print i,j,k,l,m,n

Would be a direct translation of your code (with a few lines to make it
actually do something and a fix for the last variable name).

HTH,
Mike

Efrain Marrero wrote:
i want to now how to do this in python
this is java
for(int i=1 ; i<=lim ; i++){

for(int j=i+1; j<=lim+1; j++){

....

--
________________________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://www.vrplumber.com
http://blog.vrplumber.com

Dec 9 '05 #3
In article <ma***************************************@python. org>,
Mike C. Fletcher <mc******@vrplumber.com> wrote:
Python iterates over "things" (objects), of which integer numbers are
just one possible choice. The range built-in command produces ranges of
integers which are useful for tasks such as this.

lim = 3

for i in range( 1, lim+1 ):
for j in range( i+1, lim+2):
for k in range( j+1, lim+3):
for l in range( k+1, lim+4):
for m in range( l+1, lim+5):
for n in range( m+1, lim+6):
print i,j,k,l,m,n

Would be a direct translation of your code (with a few lines to make it
actually do something and a fix for the last variable name).

Dec 9 '05 #4
Cameron Laird wrote:
In article <ma***************************************@python. org>,
Mike C. Fletcher <mc******@vrplumber.com> wrote:
Python iterates over "things" (objects), of which integer numbers are
just one possible choice. The range built-in command produces ranges of
integers which are useful for tasks such as this.

[...clip (something that begs of recursion)...]
I don't think the list comprehension helps, in this case--although
it hints at the temptation of an eval-able expression which is
briefer. More on that, later.


This goes backwards. Going forwards is left as an exercise for whomever:
def do_something(*args):
print args

def do_deeply(first, depth, lim, todo, inc, *args):
if depth < lim:
do_deeply(first+inc, depth+inc, lim, todo, inc, *args)
if first < depth:
do_deeply(first+inc, depth, lim, todo, inc, *args + (first,))
else:
do_something(*args)

do_deeply(first=1, depth=6, lim=8, todo=do_something, inc=1)
James
Dec 9 '05 #5
Cameron Laird wrote:
....
for hextuple in [(i, j, k, l, m, n)
for i in range(1, lim + 1) \
for j in range (1, lim + 2) \
for k in range (1, lim + 3) \
for l in range (1, lim + 4) \
for m in range (1, lim + 5) \
for n in range (1, lim + 6)]:
print hextuple

I don't think the list comprehension helps, in this case--although
it hints at the temptation of an eval-able expression which is
briefer. More on that, later.


from the recent "N-uples from list of lists" thread import cross

for hextuple in cross(*[xrange(1, lim+p) for p in xrange(1, 7)]):
print hextuple

Dec 10 '05 #6
Cameron Laird wrote:
In article <ma***************************************@python. org>,
Mike C. Fletcher <mc******@vrplumber.com> wrote:
Python iterates over "things" (objects), of which integer numbers are
just one possible choice. The range built-in command produces ranges of
integers which are useful for tasks such as this.
Cameron Laird wrote:
In article <ma***************************************@python. org>,
Mike C. Fletcher <mc******@vrplumber.com> wrote:
Python iterates over "things" (objects), of which integer numbers are just
one possible choice. The range built-in command produces ranges of integers
which are useful for tasks such as this.


[...clip (something that begs of recursion)...]
I don't think the list comprehension helps, in this case--although
it hints at the temptation of an eval-able expression which is briefer. More

on that, later.

I noticed my last one had duplicates. I have wasted an embarrassingly large
amount of time fixing it:

def do_something(*args):
print args

def do_deeply(first, depth, lim, inc, doit=True, *args):
if depth < lim:
do_deeply(first+inc, depth+inc, lim, inc, False, *args)
if first <= depth:
do_deeply(first+inc, depth, lim, inc, True, *args + (first,))
elif doit:
do_something(*args)

do_deeply(first=1, depth=3, lim=4, inc=1)
Dec 10 '05 #7
In article <11**********************@f14g2000cwb.googlegroups .com>,
Dan Bishop <da*****@yahoo.com> wrote:
Cameron Laird wrote:
...
for hextuple in [(i, j, k, l, m, n)
for i in range(1, lim + 1) \
for j in range (1, lim + 2) \
for k in range (1, lim + 3) \
for l in range (1, lim + 4) \
for m in range (1, lim + 5) \
for n in range (1, lim + 6)]:
print hextuple

I don't think the list comprehension helps, in this case--although
it hints at the temptation of an eval-able expression which is
briefer. More on that, later.


from the recent "N-uples from list of lists" thread import cross

for hextuple in cross(*[xrange(1, lim+p) for p in xrange(1, 7)]):
print hextuple


Tangential remarks: cross product is *very* important; why
isn't it built in? Yes, I recognize that the recipes supplied
elsewhere are quite nice.

I've seen a lot of Fortran and C code of the "for (...) {for (...) { ..."
variety. I have a deep suspicion that most of them betray
fundamental miscomprehension of physical realities. It's very,
*very* unusual for any meaningful measurement to arise across a
medium-dimension product of real intervals. I invite
counterexamples. In the meantime, I'll persist in suspecting
that such computations are symptoms of a misunderstanding.

So: cross products are valuable, but particularly so when not
limited to crosses over numeric intervals.
Dec 16 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4158
by: cyshao | last post by:
How to reset Router by programing? For some resean, we need usually reset our Router. Now, we have to Reset Router manually(shot down and reopen). Are there any method to control and reset...
0
1197
by: cyshao | last post by:
How to reset Router by programing? For some resean, we need usually reset our Router. Now, we have to Reset Router manually(shot down and reopen). Are there any method to control and reset...
12
3566
by: Xah Lee | last post by:
Of Interest: Introduction to 3D Graphics Programing http://xahlee.org/3d/index.html Currently, this introduction introduces you to the graphics format of Mathematica, and two Java Applet...
15
2770
by: Xah Lee | last post by:
On Java's Interface Xah Lee, 20050223 In Java the language, there's this a keyword “interface”. In a functional language, a function can be specified by its name and parameter specs....
2
1596
by: sengpg345 | last post by:
hi everybody. i have a project in colage for messanger but i haven't idea of socket programing in c#.net . so plz give me the guidence i socket programing. if u have row matirial or tutorial then...
0
7205
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,...
1
7008
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...
0
5594
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
1
5022
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4688
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3177
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3168
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
399
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.