Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #52399

Re: back with more issues

References <cc701481-0ecd-411b-8473-0596b4252949@googlegroups.com>
Date 2013-08-12 00:21 -0400
Subject Re: back with more issues
From Joel Goldstick <joel.goldstick@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.490.1376281271.1251.python-list@python.org> (permalink)

Show all headers | View raw


On Sun, Aug 11, 2013 at 11:33 PM, Kris Mesenbrink
<krismesenbrink@gmail.com> wrote:
> import random
>
> def player():
>     hp = 10
>     speed = 5
>     attack = random.randint(0,5)
       # add the following line to return attack value:
       return attack

>
> def monster ():
>     hp = 10
>     speed = 4
>
> def battle(player):
>     print ("a wild mosnter appered!")
>     print ("would you like to battle?")
>     answer = input()
>     if answer == ("yes"):
you don't need the parentheses around "yes"

>         return player(attack)

you can't do that above because you defined the function with no
parameters.  If you alter player to return attack  you can alter the
above line to:
           return player()

>     else:
>         print("nope")

Its a bad idea to have a function return something down one path (If
True), then return nothing down another path.
>
>
> battle()
>
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> this was a variation on a code that you guys already had helped me with,in the long run i plan to incorporate them together but as it stand i don't know how to call a specific variable from one function (attack from player) to use in another function (battle). what i want is to be able to use the variables from both player and monster to use in battle. any idea's?

I wrote some quick changes above to give you what you want.  But you
need to understand more about functions.  Your player function does
next to nothing.  It defines two variables to fixed values, then gets
a random number and returns it.  Can you try to explain what you think
each of your functions is doing?  Every line should serve a purpose,
or it shouldn't be in the function.

> --
> http://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

back with more issues Kris Mesenbrink <krismesenbrink@gmail.com> - 2013-08-11 20:33 -0700
  Re: back with more issues Joel Goldstick <joel.goldstick@gmail.com> - 2013-08-12 00:21 -0400
    Re: back with more issues Kris Mesenbrink <krismesenbrink@gmail.com> - 2013-08-11 21:35 -0700
      Re: back with more issues Joel Goldstick <joel.goldstick@gmail.com> - 2013-08-12 00:51 -0400
  Re: back with more issues Dave Angel <davea@davea.name> - 2013-08-12 05:54 +0000
    Re: back with more issues Kris Mesenbrink <krismesenbrink@gmail.com> - 2013-08-11 23:31 -0700
      Re: back with more issues Kris Mesenbrink <krismesenbrink@gmail.com> - 2013-08-11 23:57 -0700
      Re: back with more issues Dave Angel <davea@davea.name> - 2013-08-12 07:11 +0000
    Re: back with more issues Rotwang <sg552@hotmail.co.uk> - 2013-08-12 15:56 +0100
      Re: back with more issues random832@fastmail.us - 2013-08-12 15:46 -0400
        Re: back with more issues Kris Mesenbrink <krismesenbrink@gmail.com> - 2013-08-12 20:13 -0700
          Re: back with more issues MRAB <python@mrabarnett.plus.com> - 2013-08-13 04:31 +0100
          Re: back with more issues Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-08-12 23:48 -0400
          Re: back with more issues Steven D'Aprano <steve@pearwood.info> - 2013-08-13 06:22 +0000

csiph-web