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

how can you loop a code

werecatz
I'm trying to do a time/ distance calculator (like in the wiki guide)

Instead of just ending I want to be able to press or type something in and start from the begining (do a new calculation)

Expand|Select|Wrap|Line Numbers
  1. print "enter your distance/rate problem"
  2. rate= input("Rate: ")
  3. distance= input ("distance: ")
  4. print "Time:", distance/rate
that's the code I'm using.
May 2 '07 #1
3 1971
ghostdog74
511 Expert 256MB
I'm trying to do a time/ distance calculator (like in the wiki guide)

Instead of just ending I want to be able to press or type something in and start from the begining (do a new calculation)

Expand|Select|Wrap|Line Numbers
  1. print "enter your distance/rate problem"
  2. rate= input("Rate: ")
  3. distance= input ("distance: ")
  4. print "Time:", distance/rate
that's the code I'm using.
a loop ?
Expand|Select|Wrap|Line Numbers
  1. while 1:
  2.     print "enter your distance....
  3.     ...
  4.     print "Time: ...
  5.     choice = raw_input("do you want to continue: [y/n]" )
  6.     if choice in ["N","n"]:
  7.        break
  8.  
May 2 '07 #2
a loop ?
Expand|Select|Wrap|Line Numbers
  1. while 1:
  2.     print "enter your distance....
  3.     ...
  4.     print "Time: ...
  5.     choice = raw_input("do you want to continue: [y/n]" )
  6.     if choice in ["N","n"]:
  7.        break
  8.  
tried it didn't work (probably didn't put it in right)
A loop as in it goes back to the start so you can do another problem.
May 2 '07 #3
ghostdog74
511 Expert 256MB
tried it didn't work (probably didn't put it in right)
A loop as in it goes back to the start so you can do another problem.
if it doesn't work, then show your error messages or the output you have
for me it works
Expand|Select|Wrap|Line Numbers
  1. # ./test.py
  2. enter your distance/rate problem
  3. Rate: 10
  4. distance: 10
  5. Time: 1
  6. do you want to continue: [y/n]y
  7. enter your distance/rate problem
  8. Rate:
  9.  
Expand|Select|Wrap|Line Numbers
  1. # ./test.py
  2. enter your distance/rate problem
  3. Rate: 10
  4. distance: 10
  5. Time: 1
  6. do you want to continue: [y/n]n
  7. #:
  8.  
May 2 '07 #4

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

Similar topics

0
by: Charles Alexander | last post by:
Hello I am new to php & MySQL - I am trying to retrieve some records from a MySQL table and redisplay them. The data in list form looks like this: Sample_ID Marker_ID Variation ...
47
by: Mountain Bikn' Guy | last post by:
Take some standard code such as shown below. It simply loops to add up a series of terms and it produces the correct result. // sum numbers with a loop public int DoSumLooping(int iterations) {...
8
by: ben | last post by:
i have a bit of code, that works absolutely fine as is, but seems over complicated/long winded. is there anyway to shorten/simplify it? the code is below. description of it: it's like strcpy in...
2
by: Alex | last post by:
Compiler - Borland C++ 5.6.4 for Win32 Copyright (c) 1993, 2002 Borland Linker - Turbo Incremental Link 5.65 Copyright (c) 1997-2002 Borland Platform - Win32 (XP) Quite by accident I stumbled...
22
by: Jan Richter | last post by:
Hi there, the Code below shows DJBs own implementation of strlen (str_len): unsigned int str_len(char *s) { register char *t; t = s; for (;;) { if (!*t) return t - s; ++t;
8
by: Shamrokk | last post by:
My application has a loop that needs to run every 2 seconds or so. To acomplish this I used... "Thread.Sleep(2000);" When I run the program it runs fine. Once I press the button that starts the...
15
by: Mike Lansdaal | last post by:
I came across a reference on a web site (http://www.personalmicrocosms.com/html/dotnettips.html#richtextbox_lines ) that said to speed up access to a rich text box's lines that you needed to use a...
8
by: Microsoft | last post by:
I have the following loop the length contains somewhere around 1000+ items: For elemIndex = 0 To len - 1 elem = CType(doc.all.item(elemIndex), mshtml.IHTMLElement) If elem.tagName = "A" Then If...
32
by: cj | last post by:
When I'm inside a do while loop sometimes it's necessary to jump out of the loop using exit do. I'm also used to being able to jump back and begin the loop again. Not sure which language my...
2
ADezii
by: ADezii | last post by:
If you are executing a code segment for a fixed number of iterations, always use a For...Next Loop instead of a Do...Loop, since it is significantly faster. Each pass through a Do...Loop that...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
1
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: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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)...
0
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...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
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: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.