2014-04-18 14 views
1

在這裏編程新手。如何指定要存儲的輸入數量?

輸入的第一行包含整數N(個案數)。 N行跟在每行包含一個數組P的細節上。

我該如何做IO事件,以便它一直提示用戶輸入/存儲N個案例?

對於僞代碼(因爲我無法得到它的工作),我想它應該是沿着線的東西:

for however many times N: 
take P as raw_input and put it somewhere like another array? 

回答

2

這裏是你想要的一個例子:

inputs = [] 
nums = 5 #number of times to take input 
for _ in range(nums): 
    inputs.append(raw_input('Please enter text: ')) 

inputs = [] 
nums = 5 #number of times to take input 
for i in range(nums): 
    inputs.append(raw_input('Please enter input {}: '.format(i+1))) 


#Run your script 
Please enter input 1: 
Please enter input 2: 
Please enter input 3: 
Please enter input 4: 
Please enter input 5: 
相關問題