1. No Profile Picture
Contributing User
Devshed Novice (500 - 999 posts)

Join Date
Nov 2004
Location
There where the rabbits jump
Posts
556
Rep Power
15

while problem!!!!!!!!!!!!!!!

well i am tryng to make a fibonacci sequence so that everybody can say yes or it exits but heres a part of my script.

Code:
```if fib not in ["fib","ex","exit"]:
continue

if fib== "fib":

print
print "This is the Fibenocci Sequence."
print

print "1: ",a
print "2: ",b
print "3: ",c
print "4: ",d
print "5: ",e
print "6: ",f
print "7: ",g
print "8: ",h
print "9: ",i
print "10: ",j
print "11: ",k
print "12: ",l
print "13: ",m
print "14: ",n
print "15: ",o
print "16: ",p
print "17: ",q
print "18: ",r
print "19: ",s
print "20: ",t
print "21: ",u
print "22: ",v
print "23: ",w
print "24: ",x
print "25: ",y
print "26: ",z

a=raw_input("Press yes to see the next 26 numbers.")

if a not in ['yes']:
continue

if a== "yes":
print "27: ",aa
print "28: ",ab
print "29: ",ac
print "31: ",ae
print "32: ",af
print "33: ",ag
print "34: ",ah
print "35: ",ai
print "36: ",aj
print "37: ",ak
print "38: ",al
print "39: ",am
print "40: ",an
print "41: ",ao
print "42: ",ap
print "43: ",aq
print "44: ",ar
print "45: ",as
print "46: ",at
print "47: ",au
print "48: ",av
print "49: ",aw
print "50: ",ax
print "51: ",ay
print "52: ",az```
When they say yes or exit (i did not put it on yet) but then how could i break a while becasue it has a while at the start
(while a how could i make it by the continue that it just restarts that segment not the whole thing?

Last edited by netytan; December 4th, 2004 at 08:18 AM.
2. Hey Monkey,

I'm not quite following you here, maybe you could attach the full program if you haven't already fixed the problem.

Anyway, usually when you want to break from a loop you would use the break keyword. Or if the while loop is inside a function you could use return.

Mark.
3. No Profile Picture
Contributing User
Devshed Novice (500 - 999 posts)

Join Date
Nov 2004
Location
There where the rabbits jump
Posts
556
Rep Power
15
em well i ll copy and paste because u cant put a .py file up here
4. I've deleted the other thread and reopened this one to save cluttering up forums. Anyway, could you zip the .py files up using winzip etc. You should then be able to attach that .
5. No Profile Picture
Contributing User
Devshed Novice (500 - 999 posts)

Join Date
Nov 2004
Location
There where the rabbits jump
Posts
556
Rep Power
15
oh ya thats a good idea
an d i did not wat to do that other thread ok
6. No Profile Picture
Contributing User
Devshed Novice (500 - 999 posts)

Join Date
Nov 2004
Location
There where the rabbits jump
Posts
556
Rep Power
15
I am not bothering to open an other thread so it does not take any sopae or watever ok another question

could u guys show me how to use for example the module random and the numbergenerator because i just dontget it please with an example
8. I'm not sure if I understand exactly what you need but heres a code that will exit your program without any problems.

import sys
sys.exit(1)

Obviously sys.exit closes out the program. I think if you have while 1==1: then doing sys.exit(1) will close the program. If you don't have while 1==1: at the top of your program just do sys.exit().
Also, I've noticed that in all your posts your messages make almost no sense whatsoever. Try typing in complete and understandable sentences.
9. No Profile Picture
Contributing User
Devshed Novice (500 - 999 posts)

Join Date
Nov 2004
Location
There where the rabbits jump
Posts
556
Rep Power
15
ok ill try thanks

so in the while 1==1 u have to do sys.exit(1) and if u dont have it like that u just have to do sys.exit()

but what if u have while 1: would it still be sys.exit()
10. No Profile Picture
sfb
Contributing User
Devshed Novice (500 - 999 posts)

Join Date
Nov 2003
Posts
624
Rep Power
38
Whoa, wait just a minute. You don't need sys.exit, just make your program so it doesn't carry on running.

1) Assigning so many many variables must have taken you ages. It's terribly dull to do, error prone, and hard to read - stop right there and learn about loops and functions. Go on, it will only take you a few minutes.

2) The program structure is contorted and difficult to follow.
Code:
```while 1:
fib = raw_input(...)
if fib not in [...]: continue
if fib == "fib":
...
a = raw_input(...)
if a not in ["yes"]: continue
...```
It says "press yes to continue", but only continues if they don't press yes(!).

Simply, you could make a function like this:
Code:
```def fib(a, b, n):
# print the n digits of the fibonacci sequence, starting with a, b
for counter in range(n):
print a
a, b = b, a+b
return a,b

# Start the program
a, b = 1, 1

While True:
a, b = fib(a, b, 10)
choice = raw_input("Enter "yes" to see the next 10 digits")
if not choice.lower() == "yes":
break```

could u guys show me how to use for example the module random and the numbergenerator because i just dontget it please with an example
Code:
```import random
print random.randint(1, 100)```
11. No Profile Picture
Contributing User
Devshed Novice (500 - 999 posts)

Join Date
Nov 2004
Location
There where the rabbits jump
Posts
556
Rep Power
15
but where do you get the random.randint from.

but the sys.exit is when you are in a loop isnot it?

okay could you make a real life script for me to understand because i don't get it.
12. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Dec 2003
Posts
53
Rep Power
15
Originally Posted by monkeyman23555
but where do you get the random.randint from.

but the sys.exit is when you are in a loop isnot it?
.

i don't know what you're talking about when you say "where do you get the random.randint from". he just imported the random module and is using it to generate a random number. simple as that.

sys.exit can be used whenever you want your program to exit. there are always other ways, but you don't have to only use sys.exit in a loop.
13. No Profile Picture
Contributing User
Devshed Novice (500 - 999 posts)

Join Date
Nov 2004
Location
There where the rabbits jump
Posts
556
Rep Power
15
ya okay he imported it but where does he get the command random.randint from?

__module__.__name__

but where does he get that name from because can't find it in the module docs.

Thanks for the sys.exit it works now.
14. No Profile Picture
sfb
Contributing User
Devshed Novice (500 - 999 posts)

Join Date
Nov 2003
Posts
624
Rep Power
38
I found it in the module docs.

http://docs.python.org/lib/module-random.html

randint(a, b)
Return a random integer N such that a <= N <= b.
Details also available from:

Code:
```>>> import random
>>> dir(random)
>>> help(random)
>>> help(random.randint)```
but where do you get the random.randint from.

okay could you make a real life script for me to understand because i don't get it.
That is a real life script. You can type it in the interpreter and it will execute, or save it as a .py file and run it.

The random module has a method named "randint"; when you import the module, you can access the method and when you call the method, it returns a random integer in the range you specify.