os
関数によって返された変数を次のように使用できないのはなぜですか? モジュールはos
インポートされていないため、まったく問題にはなりません。Begin()
関数を呼び出して、関数os
の終了後に変数を出力すると、python は変数が定義されていないと言います。
def Begin():
os = raw_input("Choose your operating system:\n[1] Ubuntu\n[2] CentOS\nEnter '1' or '2': ")
if os != '1' and os != '2':
print "Incorrect operating system choice, shutting down..."
time.sleep(3)
exit()
else:
return os
Begin()
print os