私はpythonの初心者です。2013年に大学で勉強を始めて以来、pythonの仕組みをよく知るために一生懸命勉強しています。少し乱雑であれば申し訳ありません。
以下に私の問題を示してみましょう。次のような def 関数があります。
def thread_1():
a = input('Value UTS (100) = ')
if a > 100:
print line2
d=raw_input('Dont higher than 100. Input y to repeat : ')
d='y'
if d=='y' :
thread_1()
return a
def thread_2():
b = input('Value UAS (100) = ')
if b > 100:
print line2
d=raw_input('Dont higher than 100. Input y to repeat : ')
d='y'
if d=='y' :
thread_2()
return b
def thread_3():
c = input('Value Course (100) = ')
if c > 100:
print line2
d=raw_input('Dont higher than 100. Input y to repeat : ')
d='y'
if d=='y' :
thread_3()
def thread_4():
value_total = a*50/100+b*30/100+c*20/100
そして、これは私の表現をプログラムリストに定義します
if p==1:
thread_1()
thread_2()
thread_3()
thread_4()
最後に、このプログラムを実行します: 番号を入力する限りは問題ありませんが、最後のプログラムでは次のようなエラー コードが表示されます:
Traceback (most recent call last): File "ganjil-genap.py", line 71, in <module>
thread_4() File "ganjil-genap.py", line 36, in thread_4
value_total = a*50/100+b*30/100+c*20/100 NameError: global name 'a' is not defined
誰かが私が間違ったことを教えてもらえますか?
前もって感謝します。