2016-09-02 10 views
0

定義関数をif文に挿入するにはどうすればいいですか?定義関数を正常に関数に含めるにはどうすればいいですか?

person=int(input("select the number of any option which you would like to execute:")) 

if (person)==(1): 
    print ("please write the value for each class ") 
    main() 

def main(): 
    juvenile=(input(" number of juveniles: ")) 
    adult= (input(" number of adults:")) 
    senile=(input("number of seniles:")) 

私はそれを実行すると常にエラーが表示されます。

Traceback (most recent call last): 
    File "C:\Users\fenis\Desktop\TEST PAGE 4 GCSE CS CW.py", line 6, in <module> 
    main() 
NameError: name 'main' is not defined 
>>> 
+1

エラーをご提供ください。 –

+2

'main()'の定義を、呼び出しようとしている場所の前に移動します。 – khelwood

答えて

1

あなたはmain()が定義されていない時点でmain()を呼び出すことはできません。 main()の定義を移動して呼び出す場所の上に移動します。

def main(): 
    juvenile = input("number of juveniles:") 
    adult = input("number of adults:") 
    senile = input("number of seniles:") 

person = int(input("select the number of any option which you would like to execute:")) 

if person==1: 
    print ("please write the value for each class ") 
    main() 
+0

ありがとうございます – fenisawsome

関連する問題