2017-11-19 2 views
-1

사용자가 "END"를 입력 할 때까지 파이썬이 여러 입력을받는 프로그램을 만들려고합니다. 각 입력은 다른 행에 있어야합니다. 나는 여전히 새롭고 일반적으로 파이썬/프로그래밍을 배우므로 어떤 방법으로 이것을 할 수 있습니까? 입력을 목록으로 변환하는 방법은 무엇입니까?파이썬에서 사용자로부터 여러 입력을받는 방법

데모가 어떻게 보이는지 -

당신의 취미는 무엇입니까? 당신은 input() 기능 입력을 읽을 수

END

+3

가능한 [Python : 사용자 입력 및 명령 줄 인수] (https://stackoverflow.com/questions/70797/python-user-input-and-commandline-arguments) 중복 가능 – alfasin

+0

[사용자 입력을 읽는 방법 파이썬에서 EOF까지?] (https://stackoverflow.com/questions/46003639/how-to-read-user-input-until-eof-in-python) –

답변

0

그리기

하이킹

그림

. 사용자가 'END'를 입력 할 때까지 읽고 싶습니다. 그래서 입력을 읽고 'END'인지 확인하십시오. 그렇지 않은 경우 append 목록에 추가하면 루프가 종료됩니다. 코드에서

당신은 다음과 같이 할 수 ..

inputs = [] # list to store the inputs 

while True: # looping forever 

    data = input('Enter the data : ') # read the data from user to variable data 

    if data == 'END': # if END is read then exit the loop 
     break 

    else: 
     inputs.append(data) # otherwise, append the input to the list 

print(inputs) # display the list. 

희망이 도움이됩니다. !!

관련 문제