ここに私のコードがあります
a="yes"
b="no"
c=a[0].upper() + a[1:]
d=b[0].upper() + b[1:]
e=a.upper()
f=b.upper()
def shut_down(s):
if s == a or c or e:
return "Shutting down..."
if s == b or d or f:
return "Shutdown aborted"
else:
return"yeah"
そのため、関数を呼び出しても正しく実行されません (すべての if ステートメントを実行しません)。私は Python が初めてで、これがなぜなのかわかりませんが、次のように作業をやり直すと、次のように機能します。意図されました
a="yes"
b="no"
c=a[0].upper() + a[1:]
d=b[0].upper() + b[1:]
e=a.upper()
f=b.upper()
def shut_down(s):
if s == a:
return "Shutting down..."
if s== e:
return "Shutting down..."
if s ==c:
return "Shutting down..."
if s == b:
return "Shutdown aborted!"
if s == d:
return "Shutdown aborted!"
if s == f:
return "Shutdown aborted!"
else:
return "Sorry, I didn't understand you."
なぜこれが起こっているのか誰か教えてください