0
def namemc():
global mcname
agree = ""
print("")
mcname = input("Enter your name... ")
if mcname == "":
mcname = "Red"
mcname = mcname.capitalize()
print("")
print("OAK")
txt("Right!\n"
"So your name is " + mcname + "!")
print("")
while agree != "yes" or "no":
agree = input("yes/no ")
if agree == "yes":
print("")
return mcname
elif agree == "no":
agree = ""
namemc()
else:
print("")
print("Please type yes or no.")
print("")
私は、この名前が気に入らなければ、自分のキャラクターに名前を付けるオプションと気をつけるオプションをユーザに与える機能を作成しようとしています。Python 3 - 文の繰り返しユーザ入力
すべてが機能していることをテストするために、関数が返ったらprintステートメントを呼び出しました。
ユーザーが選択したファーストネームをユーザーが受け入れると、すべてうまく動作しているようです。
Enter your name... glitch
OAK
Right!
So your name is Glitch!
yes/no yes
Glitch
ただし、ユーザーが気を付け直すと、関数はユーザー入力を2回呼び出します。
Enter your name...
OAK
Right!
So your name is Red!
yes/no no
Enter your name... glitch
OAK
Right!
So your name is Glitch!
yes/no yes
yes/no yes
Glitch
私はどこかのコーディングで間違いを犯しましたか?
ありがとう、
グリッチ。
、変更すべき
ありがとうを続けて、私はリターンの機能だけでなく、変数のために働いて実現しませんでした。 – Glitch
@Glitch "内部関数"は値を返し、 "外部関数"もその値を返します。 –