473,745 Members | 2,189 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

7 New Member
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 1858
ilikepython
844 Recognized Expert Contributor
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 Recognized Expert Expert
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
5002
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 top of the file and looping forever? Thanks, I'm new at this. Orin Hargraves
5
33658
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, i.e. not officially supported (in Opera it looks good though). Is there an accepted way of accomplishing this? Thanks, **Daniel
34
2679
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 <limits.h> #include <stdlib.h> int main(void) {
16
4478
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 specified.". I don't understand this result. Should I modify something ? Thanks
0
8795
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9486
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9344
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9214
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8218
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 project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4572
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3286
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 we have to send another system
2
2759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2195
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.