내 프로그램 askTheUser()
도 내가 원하는 방식으로 작동하지만 어떻게 든 "for"또는 "while"루프를 포함하도록 변경해야합니다. 어떤 제안? 결말 결과는 0과 1의 목록으로되어 있습니다. 예를 들어, [1,1,1,1,1]은 모든 주사위를 다시 굴리려는 것입니다.코드를 작성했지만 잠시 또는 루프를 사용해야합니다
import random
def askTheUser():
userList = []
choice = input("Would you like to re-roll dice 1? If so, enter 'Yes'. If not, enter 'No'.")
if choice == str("Yes"):
userList.append(1)
else:
userList.append(0)
choice2 = input("Would you like to re-roll dice 2? If so, enter 'Yes'. If not, enter 'No'.")
if choice2 == str("Yes"):
userList.append(1)
else:
userList.append(0)
choice3 = input("Would you like to re-roll dice 3? If so, enter 'Yes'. If not, enter 'No'.")
if choice3 == str("Yes"):
userList.append(1)
else:
userList.append(0)
choice4 = input("Would you like to re-roll dice 4? If so, enter 'Yes'. If not, enter 'No'.")
if choice4 == str("Yes"):
userList.append(1)
else:
userList.append(0)
choice5 = input("Would you like to re-roll dice 5? If so, enter 'Yes'. If not, enter 'No'.")
if choice5 == str("Yes"):
userList.append(1)
else:
userList.append(0)
return userList
나는'break' 또는'continue' 문이 필요 없다고 생각합니다. 'continue'는 단순히 불필요한 반면'break'는 코드가 언 롤링 된 원고와 다르게 동작합니다. – Blckknght
옵션이 '아니오'이면 다음 루프에 사용하지 않습니다. na ?? – rajpython
코드는 각 다이를 다시 롤링할지 여부를 묻는 의미입니다.나는 주사위 1-3을 다시 굴리지 않고도 4 번 주사위를 굴릴 수 있다고 생각합니다. – poke