×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# What's wrong?

 Forum Search FAQs Links MVPs

## What's wrong?

(OP)
The following runs just one time out of five:

import math
for a1 in range (1,9,1):
for a2 in range (1,9,1):
for a3 in range (1,9,1):
for a4 in range (1,9,1):
for a5 in range (1,9,1):
for a6 in range (1,9,1):
for a7 in range (1,9,1):
for a8 in range (1,9,1):
for a9 in range (1,9,1):
if a1+a2+a3+a4+a5+a6+a7+a8+a9 == 11:
print a1,a2,a3,a4,a5,a6,a7,a8,a9

What am I doing wrong?

Edwin M.
Replies continue below

### RE: What's wrong?

runs fine over here
very slowly however

can you give more info re the problems you are having?
how are you running the script?

### RE: What's wrong?

(OP)
Thanks Justin. I enter the lines you see in the Python Idle Shell and press [Enter].  When it works, I get the blue listings of the 9 numbers, indeed slowly, but something always starts within 15 seconds.  When it does not work, it prints >>>  and then nothing.  I am trying to write a Sudoku program, which would require 26 more blocks like this one - looks hopeless. I guess it is not possible to write just one line for a1 to a9 instead of 9, i.e. something like [for a1,a2 in range so-and-so]. In practice, some 2-4 of the lines would have single values, not a range.  However, I am a rank beginner.  It seems to me that this sort of thing ran much faster in Turbo Pascal, and the fault may be with Windows XP, even though I have 2 GB RAM.

Edwin M.

### RE: What's wrong?

I don't know why it's not working in the idle shell, I would suspect a problem with the cut and paste.  When I paste it into a python shell under linux it runs fine.  Get the cut and paste our of the mix and put it all in a file and run it.

You realize that there's no reason to go range(1,9), because any time any of your counters goes above 3, the sum will always be > 11.  You may as well do range(1,3), it'll run faster.

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

#### Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!