2017-11-16 11 views
-2

スクリプトを作成しましたが、.pyファイルの電子メールの添付ファイルとして開くと、入力に応答して実行した後に終了します。私はこれをやめるために何ができますか?それは場合に役立ちます。ここのコードです:あなたは簡単にちょうど終了からそれを維持するために、スクリプトの末尾にinput()を置くことができスクリプトの実行後に.pyファイルを終了させないようにする

# Write a program to solve an ancient Chinese puzzle: We count 35 heads 
# and 94 legs among the chickens and rabbits on a farm. How many rabbits 
# and how many chickens are there? 


# Inputs the number of heads and legs, respectively. 
# Makes sure it is read as an integer. 

h=input('Enter the number of heads:') 
heads=int(h) 
le=input('Enter the number of legs:') 
legs=int(le) 

# Executes a while loop while the total number of rabbits is less 
# than or equal to 35. 

rabbits=0 
while rabbits <= heads: 
    chickens = heads - rabbits 

# Prints the result if there are 35 heads and 94 legs found. 

    if 2 * chickens + 4 * rabbits == legs and chickens + rabbits == heads: 
     print('There are', rabbits, 'rabbits and', chickens, 'chickens.') 
     break 
    rabbits+=1 



if 2 * chickens + 4 * rabbits != legs or chickens + rabbits != heads: 
    print('No answer.') 
+0

最後に 'input()'を追加します。 –

+2

'input(" press return ")' –

答えて

1

ご存知のように、input()は、標準入力から文字列を取り込み、この状況で必要でないものを自由に入力できます。