0
저는 프로그래밍에 비교적 익숙하지 않으므로 코드에 약간의 딸꾹질이있는 경우 놀라지 마십시오.하지만이 코드가 반복적으로 반복되는 것으로 보입니다 , 모든 것을 이해하지 못합니다. 이 함수를 실행하는 실제 코드를 살펴 보았지만 괜찮아 보였다. 그래서 루프 자체를 만드는이 코드에서 오류를 찾을 수 없습니다.Python 2.7.3 While 루프가없는 코드 루프
def randomevents(yourhp):
turn = 10
while turn > 0:
time.sleep(0.1)
happening = int(random.randint(1,6))
time.sleep(0.1)
if yourhp < 1:
turn = 0
print "You managed to escape the dungeon, by dying that is"
elif happening == 1:
turn = turn - 1
thebeast(yourhp)
elif happening == 2:
item(sword, spear)
turn = turn - 1
elif happening in [3, 4, 5]:
friend()
turn = turn - 1
print "Well done! You escaped the dungeon! (Either by running out of it, or by having your soul sent to another world)"
useless = str(input("Are you satsified with yourself?: "))
감사합니다 : 코드를 반복
def thebeast(yourhp):
foe = "Thisisirrelevant"
enemy = int(random.randint(1,4))
if enemy == 1:
foe = "skeleton"
elif enemy == 2:
foe = "man with crazy eyes"
else:
foe = "dog, a big and scary dog"
monsteract = 1
dmg = 0
print "-=~-=~-=~-=~-=~-=~-=~-=~-=~-=~-=~-=~"
time.sleep(0.1)
print " C O M B A T"
time.sleep(0.1)
print "-=~-=~-=~-=~-=~-=~-=~-=~-=~-=~-=~-=~"
time.sleep(0.1)
print "You encounter a " + foe
time.sleep(0.5)
while monsteract == 1:
comb = str(input("What do you do to the " + foe + "?" + " Do you feel like jabbing it or stabbing it?"))
if comb in ["s", "S", "Stab", "STAB", "stab"]:
if spear == 1:
dmg = int(random.randint(1,4))
elif sword == 1:
dmg = int(random.randint(1,3))
else:
dmg = int(random.randint(1,5))
elif comb in ["j", "J", "Jab", "JAB", "jab"]:
if spear == 1:
dmg = int(random.randint(1,3))
elif sword == 1:
dmg = int(random.randint(1,4))
else:
dmg = int(random.randint(1,5))
if dmg == 1:
print "You slay the " + foe + " with graceful ease"
time.sleep(0.5)
monsteract = 0
else:
enemydmg = int(random.randint(1,3))
print "The " + foe + " strikes you for " + str(enemydmg) + " damage"
time.sleep(0.3)
print "That didn't work out as planned, but you pull yourself together and prepare to strike the " + foe
time.sleep(0.3)
yourhp = yourhp - enemydmg
if yourhp < 0:
yourhp = 0
print "You have " + str(yourhp) + " health left"
time.sleep(0.3)
if yourhp < 1:
print "The " + foe + " has slain you, well done, you're dead, on the bright side the innocent "
print foe + " is still alive! Every life counts, even that of a " + foe + "."
monsteract = 0
return thebeast(yourhp)
(문제가이 코드에없는 경우 다음 그 아래 코드에게 그것을 반복)!
"코드 루프 자체"가 의미하는 바를 명확히 할 수 있습니까? 코드가 다시 실행되면 어떤 섹션입니까? 몇 번이나 비빔을 부르면됩니다 (일어난다면 1과 같습니다). – yechezkel
코드의 다른 부분은 어디에 있습니까? 칼, 창? 친구()? – Yugi
소드 스피어와 친구는 관련없는 부분이며 전체 프로그램에 포함되지만 표시되는 코드에는 영향을 미치지 않습니다. 즉 루핑 문제가있는 곳입니다. 제가 그것이 스스로를 반복한다고 말하면, "thebeast (yourhp)"가 한 번 실행되면 곧 영원히 실행된다는 것을 의미합니다. 코드가 friend(), thebeast() 및 item() 사이를 임의로 전환해야하지만. 또한 "회전"변수의 기능이 작동하지 않는 것 같습니다. 코드가 끝나지 않고 반복되기 때문입니다. –