Here's the code I need to loop:

dmg = random.randrange(1, 10, 1)
        print "You have decided to attack the giant rat."
        ratHP = 100
        ratHPN = ratHP-dmg
        print "you did" , dmg , "damge to the rat, giving it" , ratHPN , "left"
        ratHP = ratHPN

If you need the entire code;

import random
print ">>If you don't type one of the choices exactly right, you'll need to restart<<"
print "Welcome, to this text adventure!"
name = raw_input("Please enter your name:")
print "So your name is " + name + "?"
raw_input("Press ENTER")
userHP = 100
print "Which dungeon do you wish to go to?"
print "Hope"
print "Grassy"
dungeon1 = raw_input("Which dungeon:")
if dungeon1 == "Grassy":
     print "So, you have chosen the Grassy Dungeon..."
     raw_input("Press ENTER")
     print "After exploring the caves, for 15 minutes, you run into a giant rat."
     raw_input("Press ENTER")
     print "Attack"
     print "Run"
     battle = raw_input("Select your action:")
     if battle == "Attack":
        dmg = random.randrange(1, 10, 1)
        print "You have decided to attack the giant rat."
        ratHP = 100
        ratHPN = ratHP-dmg
        print "you did" , dmg , "damge to the rat, giving it" , ratHPN , "left"
        ratHP = ratHPN
        
                
if dungeon1 == "Hope":
    print "So, you have chosen the Hope Dungeon..."
    raw_input("Press ENTER")

Edited 6 Years Ago by DocBreen: n/a

Here is a possibility

print "You have decided to attack the giant rat."
        ratHP = 100
        while ratHP > 0:
            dmg = min(ratHP, random.randrange(1, 10, 1))
            print "you did %d damge to the rat, giving it %d left" % (dmg, ratHP-dmg)
            ratHP -= dmg
        print "The rat is dead !"

Edited 6 Years Ago by Gribouillis: n/a

This question has already been answered. Start a new discussion instead.