0
コードを2回貼り付けて行を追加することなく、 "if direction == north:"を "if direction = south"に接続する方法はありますか?Python 3のコードを接続する
direction = input('do you want to travel north or south?')
if direction =='north':
print('You chose North')
print('An iron gate block your path')
print('You need a bronze key to open it')
print('You will have to go South')
if direction == 'south':
print('You chose South')
time.sleep(1)
print('The path leads you to the Deep woods of Mirkwood')
南北よりも方向が北の場合は、異なる動作があります。共通の声明は1つしかありません。その理由でそれらを接続したいですか?または、何を達成したいですか? –
コードを重複排除するほうがずっと簡単なので、接続したい –
アクションが完全に異なる場合は、2つのifステートメントが必要です。 –