Passing a variable between Python functions -
i new python , coding , trying figure out how pass result of 1 function calling function variable passed can used within calling function.
in code below, error states that:
global name 'quiz' not defined.
my intent pass string printed based upon user input.
difficulty = raw_input("please enter level of difficulty: easy, medium, or hard: ") def test_method(difficulty): if difficulty == 'easy': quiz = "yup - quiz me" else: quiz = "nope - yikes!" return quiz
i've tried using print quiz
here , expected string prints. pass quiz variable calling function , print result there.
def test_call(difficulty): test_method(difficulty) print quiz test_call(difficulty)
just assign , / or return quiz
def test_call(difficulty): quiz = test_method(difficulty) print quiz return quiz
Comments
Post a Comment