If I understand your problem correctly all you need to do is use the name of the function to call it ie:<br>
<br>
def func():<br>
print "hello world"<br>
<br>
func()<br>
<br>
would give the output<br>
<br>
"hello world"<br><br><div><span class="gmail_quote">On 7/10/05, <b class="gmail_sendername">Nathan Pinno</b> <<a href="mailto:falcon3166@hotmail.com">falcon3166@hotmail.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi all,<br><br> How do I make Python get a def? Is it the "get" function, or something<br><br>else? I need to know so that I can get a def for that computer<br>MasterMind(tm) game that I'm writing.<br><br> BTW, I took your advice, and wrote some definitions for my Giant
<br>Calculator program. Might make the code easier to read, but harder to<br>code<br>because I have to keep going to the top to read the menu. Not that fun,<br>but<br>necessary for a smooth program, I guess.<br><br> Nathan Pinno
<br><br> "Steven D'Aprano" <<a href="mailto:steve@REMOVETHIScyber.com.au">steve@REMOVETHIScyber.com.au</a>> wrote in message<br>news:pan.2005.07.03.02.30.28.82992@REMOVETHIScyber.com.au...<br> > On Sat, 02 Jul 2005 00:25:00 -0600, Nathan Pinno wrote:
<br> >> Hi all.<br> >> How do I make the computer generate 4 random numbers for the<br>guess? I<br>want<br> >> to know because I'm writing a computer program in Python like the<br>game<br> >> MasterMind.
<br> > First you get the computer to generate one random number. Then you<br>do it<br> > again three more times.<br> > If you only need to do it once, you could do it this way:<br> > import random # you need this at the top of your program
<br> > x0 = random.random()<br> > x1 = random.random()<br> > x2 = random.random()<br> > x3 = random.random()<br> > But if you need to do it more than once, best to create a function<br>that<br> > returns four random numbers in one go.
<br> > def four_random():<br> > """Returns a list of four random numbers."""<br> > L = [] # start with an empty list<br> > for i in range(4):<br> > L.append
(random.random())<br> > return L<br> > and use it this way:<br> > rand_nums = four_random()<br> > # rand_nums is a list of four numbers<br> > print rand_nums[0] # prints the first random number<br>
> print rand_nums[3] # prints the last one<br> > or like this:<br> > alpha, beta, gamma, delta = four_random()<br> > # four names for four separate numbers<br> > Steven.<br> > <a href="http://mail.python.org/mailman/listinfo/python-list">
http://mail.python.org/mailman/listinfo/python-list</a><br><br><br>_______________________________________________<br>Tutor maillist - <a href="mailto:Tutor@python.org">Tutor@python.org</a><br><a href="http://mail.python.org/mailman/listinfo/tutor">
http://mail.python.org/mailman/listinfo/tutor</a><br></blockquote></div><br>