0
def secondscene():
  second_options = ['1','2','3','4']
  second_choice = ""
  n = 25
  while n > 0:
    print('''The lion has''', n, '''health, how do you attack the lion:
1.  Slash
2.  Chop
3.  Stab
4.  Block''')
    second_choice = input(str('Please enter a number between 1-3:'))
    if second_choice == second_options[0]:
      slash()
    else:
      print('please input one of the following listed numbers')

def slash():
  import random
  s = random.randint (1,10)
  n = n - s

Can someone please explain to me how to use "n" in another function then use that function in the if statement. I'm trying to get the attacks all to do different damage. Thanks.

1
  • 1
    You should pass the variable as an argument to the function and then the function should return a value. Commented May 1, 2021 at 16:20

1 Answer 1

1

That's a really basic question and you should start to see how to use POO in python which can be usefull for you.

def secondscene():
  second_options = ['1','2','3','4']
  second_choice = ""
  n = 25
  while n > 0:
    print('''The lion has''', n, '''health, how do you attack the lion:
1.  Slash
2.  Chop
3.  Stab
4.  Block''')
    second_choice = input(str('Please enter a number between 1-3:'))
    if second_choice == second_options[0]:
      n = slash(n)
    else:
      print('please input one of the following listed numbers')

def slash(n):
  import random
  s = random.randint (1,10)
  n = n - s
  return n
Sign up to request clarification or add additional context in comments.

1 Comment

Oh wow thanks man appreciate it, sorry I'm a beginner

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.