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

"for x in range(1,100):" how do i make it stop once i get one right?

so im writing this program. i wont bother with posting the whole thing, cause its like 200 lines and ive barely started. (huge potensial for error, the way i like it)

anyways, in the part ive completed of my program, theres a very large chance that the program will not be able to execute. so i put this bugger on top of it:

for x in range(1,100):

when i run my program, it works like 3 or 4 times. the problem is, it then prints all the individual answers it got 3 or 4 times. so my question is, how do i make it print only the first answer it gets?

any help is apprechiated. :)
May 28 '07 #1
2 1843
ilikepython
844 Expert 512MB
so im writing this program. i wont bother with posting the whole thing, cause its like 200 lines and ive barely started. (huge potensial for error, the way i like it)

anyways, in the part ive completed of my program, theres a very large chance that the program will not be able to execute. so i put this bugger on top of it:

for x in range(1,100):

when i run my program, it works like 3 or 4 times. the problem is, it then prints all the individual answers it got 3 or 4 times. so my question is, how do i make it print only the first answer it gets?

any help is apprechiated. :)
I don't really understand what you are trying to do. Are you trying to break out of the for loop when something happens:
Expand|Select|Wrap|Line Numbers
  1. for x in range(1, 100):
  2. # something happens
  3.     break            #breaks out of the loop
  4.  
May 28 '07 #2
bartonc
6,596 Expert 4TB
so im writing this program. i wont bother with posting the whole thing, cause its like 200 lines and ive barely started. (huge potensial for error, the way i like it)

anyways, in the part ive completed of my program, theres a very large chance that the program will not be able to execute. so i put this bugger on top of it:

for x in range(1,100):

when i run my program, it works like 3 or 4 times. the problem is, it then prints all the individual answers it got 3 or 4 times. so my question is, how do i make it print only the first answer it gets?

any help is apprechiated. :)
I don't quite follow you, but it could just be a matter of indentation:
Expand|Select|Wrap|Line Numbers
  1. >>> for i in range(5):
  2. ...     print 'testing in loop %d' %i
  3. ...     print 'test value = %d' %(i**2)
  4. ...     
testing in loop 0
test value = 0
testing in loop 1
test value = 1
testing in loop 2
test value = 4
testing in loop 3
test value = 9
testing in loop 4
test value = 16
Expand|Select|Wrap|Line Numbers
  1. >>> for i in range(5):
  2. ...     print 'testing in loop %d' %i
  3. ...     
  4. # by de-indenting here only the last value shows up
  5. >>> print 'test value = %d' %(i**2)
testing in loop 0
testing in loop 1
testing in loop 2
testing in loop 3
testing in loop 4

test value = 16
>>>
May 28 '07 #3

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

Similar topics

5
by: Orin Hargraves | last post by:
I'm formatting data in a text file using a "For Each aPara" statement along with a "Next aPara." How do I make the thing stop when it reaches the end of the file, rather than starting again at the...
5
by: Daniel Haude | last post by:
Hi guys, I'm using a height="100%" attribute in a <table> tag to get the obvious effect (a table which fills the entire available space). html-tidy, however, complains that this is proprietary,...
34
by: Frederick Gotham | last post by:
Is the domestic usage of the C "for" loop inefficient when it comes to simple incrementation? Here's a very simple program that prints out the bit-numbers in a byte. #include <stdio.h> #include...
16
by: Tantale | last post by:
I used this serviec to check my webpage http://www.jmrw.com/Abroad/Barcelone/index.htm Made with Dreamweaver 8. The result is 206 errors, most of them "end tag omitted, but OMITTAG NO was...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.