def getInputの "adj"変数をどのように使って形容詞()に接続するのか、私はユーザーからの入力を得ることができるようにしようとしています。ユーザが入力する多くの形容詞。このプロジェクトの学生として、私はユーザー定義関数しか使用できません。あるユーザ定義関数のローカル変数を別のユーザ定義関数にどのように使用しますか?
import random
def getInput():
insult = input("Enter number of insults you want generated: ")
target = input("Enter the targets name: ")
adj = input("Enter number of adjectives you want in your insults: ")
def adjective():
adjectives = ("aggressive", "cruel", "cynical", "deceitful", "foolish", "gullible", "harsh", "impatient", "impulsive", "moody", "narrow-minded", "obsessive", "ruthless", "selfish", "touchy")
for adj in adjectives:
print(random.choice(adjectives))
break
?本当に 'getInput'関数が必要ですか? –
'' 'adjective''を引数付きで定義する - def' '' '' '' '' ... '' '、' 'getInput'''からadjを返し、' '形容詞' 'に戻り値を渡します。 ''。 https://docs.python.org/3/tutorial/controlflow.html#defining-functions – wwii
「複数の」値を返すことができます: 'return insult、target、adj'それは本当に*複数の値ではなく、そのタプル、 'insult、target、adj = getInput()'のように関数を呼び出すことができます。 – cdarke