나는 유령이 나오는 집을 통해 모험 게임 인 파이썬 프로그램을 만들고 있습니다. 그 중 큰 것 중 하나는 owned_items
이라는 목록입니다. 이것은 집에서 그들을 찾거나 처음에 그들에게 random.choice
으로 주어질 때 그것에 덧붙여지는 "성냥 상자"또는 "토치"와 같은 문자열로 표현되는 항목을 얻습니다. 때로는 상황을 제시 할 때 특정 항목이 있는지 여부에 따라 선택 항목이 달라집니다.Python : if 문을 실행하지 않고 출력하기
내 코드 :
#bullets is the variable for pistol ammo. During my testing of this function, it is at 5 when it should start
bullets=5
owned_items=[]
ronald_items=["a glass bottle", "a pistol", "a torch", "a small glass of oil", "a box of matches", "a can of spray paint", "a small knife", "a pair of surgical gloves", "a blessed amulet"]
owned_items.append(random.choice(ronald_items))
ronald_items.remove(owned_items[0]
owned_items.append(random.choice(ronald_items))
ronald_items.remove(owned_items[1])
#This part is in the actual definition where the problem appears when it should run
def skeleton_choice():
if "a glass bottle" in owned_items:
print('type "glass bottle" to attack the skeletons with that bottle')
if "a pistol" in owned_items and bullets>1:
print('type "shoot" to try firing your pistol at the skeletons')
if "a small knife" in owned_items:
print('type "small knife" to use your small knife against the skeletons')
if "a kitchen knife" in owned_items:
print('Type "kitchen knife" to use your kitchen knife against the skeletons')
if "a blessed amulet" in owned_items:
print('Type "amulet" to use the blessed amulet to make this a fairer fight')
print('Type "hands" to just fight the skeletons with your body')
print('Type "run" to try and get away from the skeletons')
심지어 내가 문, 지문의 어느 것도 표시하지 않는 경우 내가이있는 항목의 3을 가지고 있음을 알고있을 때. 엘프와 다른 것보다는 ifs를 사용하고 있습니다. 왜냐하면 내가 가지고있는 모든 것에 대한 인쇄물을 보여주기를 원하기 때문입니다. 예를 들어 유리 병과 부엌 칼이있는 경우 병과 칼에 대한 인쇄 문구를 제공해야합니다.
완전한 코드이고'def skeleton_choice()'에서 들여 쓰기 오류를 무시하면 함수가 실행되지 않도록 함수를 호출하지 않습니다. – roganjosh
함수가 잘못된 의도를 가지고 있고'def skeleton_choice (input) '처럼 입력이 없다고 생각합니다. – Bryan
질문과 관련이 있는지 또는 복사 및 붙여 넣기에 실패했는지 모르겠지만 if는 스켈레톤의 sk와 일치 해, def가 아니다. 내가보고있는 들여 쓰기에는 아무런 문제가 없습니다. –