How does xrange() work inside of a while loop?
<p>this is sort of a follow up question to a question I had <a href="http://codereview.stackexchange.com/questions/15778/how-can-i-make-this-code-better#comment16852528_12519166">yesterday</a>. Im a newbie to python and currently teaching myself using LPTHW by Zed Shaw. The code below is broken and i could use some help fixing it, im trying to make a random number generator for use with RPGs.</p>

<pre><code>from random import randint
name = raw_input('\n Hello there. Please Type in your name &gt; ')

print """
Hello {} &amp; welcome to the Random Number Generator by Ray Weiss.
""".format(name)

upper = int(raw_input('Enter the type of dice you want to roll &gt; '))

n = int(raw_input("How many D{} you'd like to roll? ".format(upper)))

for _ in xrange(n):
    print randint(1, upper)

prompt = """
Would you like to roll another D{}? Type 'yes', 'no', or 'quit'
""".format(upper)

answer = raw_input(prompt)

while answer == "yes":
    for _ in xrange(n):
            print randint(1, upper)
            prompt = """
            Would you like to roll another D{}? Type 'yes', 'no', or 'quit'
            """.format(upper)
            answer = raw_input(prompt)

if answer == "no":
    upper = int(raw_input('Enter the type of dice you want to roll &gt; '))
    n = int(raw_input("How many D{} you'd like to roll? ".format(upper)))
    for _ in xrange(n):
        print randint(1, upper)
        prompt = """
        Would you like to roll another D{}? Type 'yes', 'no', or 'quit'
        """.format(upper)
        answer = raw_input(prompt)

if answer == "quit":
    print """
    Thank you {} for using the D{} RNG by Ray Weiss! Goodbye!
    """.format(name, upper)
</code></pre>

<p>Ideally what i want to happen is that it asks me first how many sided die i want and how many dice i want to roll. after that, i want it to ask me if i want to roll that same die and amount again, if i say yes, then it does it. if i say no, i want it to go back and ask me what sided die and how many die i want to roll again. </p>

<p>Edit: I think this code is a little better but its still not working</p>

<pre><code>from random import randint

def roll(sides, num_of_dices):
    return [randint(1, sides) for i in range(num_of_dices)]

prompt = "&gt; "

# Main Program

num_of_dices = input(prompt)
sides = input(prompt)


while True:
  results = roll(sides, num_of_dices)
  print results

  s = input(prompt)
  if s == 'quit':
      break
</code></pre>
