2017-10-31 11 views
0
def characterName(name): 
    print("What would you like to name your character?") 
    name = input() 
    name = str(name) 

return characterName(name) 

def displayIntro(): 
    print(name + ' are in a land full of dragons. In front of ' + name) 
    print(', ' + name + ' see two caves. In one cave, the dragon is friendly') 
    print('and will share his treasure with ' + name + '. The other dragon') 
    print('is greedy and hungry, and will eat ' + name + ' on sight.') 
    print() 

なぜ私に型エラーを与え続けますか?私は基本的に変数 'name'を定義ブロックから戻そうとしているので、他のブロックでも使用できます。問題は、私は少しそれを混乱しようとすると、私はエラーが表示されます: '名前'は定義されていません。だから私は何が間違っているのか分からない。ありがとう!TypeError:missing 1必要な位置引数

+0

こんにちは、あなたの質問に[tag:python]タグを追加してください。 –

答えて

0

私が見ている問題は、displayIntro()のメソッドのcharacterName()を呼び出して、変数の名前を取得していないことです。私はあなたがこのようにしたいかどうか分からないが、以下はあなたの問題に対する私の解決策である。

def characterName(): 
    print("What would you like to name your character?") 
    name = input() 
    name = str(name) 
    return name 

def displayIntro(): 
    name = characterName() 
    print(name + ' are in a land full of dragons. In front of ' + name) 
    print(', ' + name + ' see two caves. In one cave, the dragon is friendly') 
    print('and will share his treasure with ' + name + '. The other dragon') 
    print('is greedy and hungry, and will eat ' + name + ' on sight.') 
    print() 

displayIntro() 
関連する問題