Skip to main content
replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

This is sort of a follow up to my post yesterdayyesterday. I'm a relative newbie to Python and before I made a d20 dice roller for RPGs. Now I've made a dice roller for any type of dice, and I would love some feedback on this code.

from random import randint

def roll(sides, number_of_dice):
    """Rolls Dice."""
    return [randint(1, sides) for i in range(num_of_dice)]

prompt = """
Would you like to roll the same combination of dice {}? 
Please type 'yes', 'no', or 'quit'
"""

# Main Program

name = raw_input("\nPlease tell me your name > ")

print """
Hello {} and welcome to an RPG Dice Roller by Ray Weiss.
Please type quit when prompted to exit or use CNTRL-C. 
Thanks to everyone at Stack Overflow etc. for the help. 
""".format(name)

sides = input("\nHow many sides do you want on your dice? > ")
num_of_dice = input("\nHow many {} sided dice do you want to roll? >".format(sides))
results = roll(sides, num_of_dice)
print results

roll_again = raw_input(prompt.format(name))

while True:
    
    if roll_again == "yes":
        results = roll(sides, num_of_dice)
        print results
        roll_again = raw_input(prompt.format(name))

    if roll_again == "no": 
        sides = input("How many sides do you want on your dice? > ")
        num_of_dice = input("\nHow many {} sided dice do you want to roll? >".format(sides))
        results = roll(sides, num_of_dice)
        print results
        roll_again = raw_input(prompt.format(name))
    
    if roll_again == "quit":
        print """
Thank you {} for using this RPG Dice Roller by Ray Weiss! Goodbye!
        """.format(name)
        break

This is sort of a follow up to my post yesterday. I'm a relative newbie to Python and before I made a d20 dice roller for RPGs. Now I've made a dice roller for any type of dice, and I would love some feedback on this code.

from random import randint

def roll(sides, number_of_dice):
    """Rolls Dice."""
    return [randint(1, sides) for i in range(num_of_dice)]

prompt = """
Would you like to roll the same combination of dice {}? 
Please type 'yes', 'no', or 'quit'
"""

# Main Program

name = raw_input("\nPlease tell me your name > ")

print """
Hello {} and welcome to an RPG Dice Roller by Ray Weiss.
Please type quit when prompted to exit or use CNTRL-C. 
Thanks to everyone at Stack Overflow etc. for the help. 
""".format(name)

sides = input("\nHow many sides do you want on your dice? > ")
num_of_dice = input("\nHow many {} sided dice do you want to roll? >".format(sides))
results = roll(sides, num_of_dice)
print results

roll_again = raw_input(prompt.format(name))

while True:
    
    if roll_again == "yes":
        results = roll(sides, num_of_dice)
        print results
        roll_again = raw_input(prompt.format(name))

    if roll_again == "no": 
        sides = input("How many sides do you want on your dice? > ")
        num_of_dice = input("\nHow many {} sided dice do you want to roll? >".format(sides))
        results = roll(sides, num_of_dice)
        print results
        roll_again = raw_input(prompt.format(name))
    
    if roll_again == "quit":
        print """
Thank you {} for using this RPG Dice Roller by Ray Weiss! Goodbye!
        """.format(name)
        break

This is sort of a follow up to my post yesterday. I'm a relative newbie to Python and before I made a d20 dice roller for RPGs. Now I've made a dice roller for any type of dice, and I would love some feedback on this code.

from random import randint

def roll(sides, number_of_dice):
    """Rolls Dice."""
    return [randint(1, sides) for i in range(num_of_dice)]

prompt = """
Would you like to roll the same combination of dice {}? 
Please type 'yes', 'no', or 'quit'
"""

# Main Program

name = raw_input("\nPlease tell me your name > ")

print """
Hello {} and welcome to an RPG Dice Roller by Ray Weiss.
Please type quit when prompted to exit or use CNTRL-C. 
Thanks to everyone at Stack Overflow etc. for the help. 
""".format(name)

sides = input("\nHow many sides do you want on your dice? > ")
num_of_dice = input("\nHow many {} sided dice do you want to roll? >".format(sides))
results = roll(sides, num_of_dice)
print results

roll_again = raw_input(prompt.format(name))

while True:
    
    if roll_again == "yes":
        results = roll(sides, num_of_dice)
        print results
        roll_again = raw_input(prompt.format(name))

    if roll_again == "no": 
        sides = input("How many sides do you want on your dice? > ")
        num_of_dice = input("\nHow many {} sided dice do you want to roll? >".format(sides))
        results = roll(sides, num_of_dice)
        print results
        roll_again = raw_input(prompt.format(name))
    
    if roll_again == "quit":
        print """
Thank you {} for using this RPG Dice Roller by Ray Weiss! Goodbye!
        """.format(name)
        break
edited tags
Link
RubberDuck
  • 30.9k
  • 6
  • 71
  • 174
deleted 19 characters in body; edited tags
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

This is sort of a follow up to my post yesterday Im. I'm a relative newbie to pythonPython and before iI made a d20 dice roller for rpgs, now i'veRPGs. Now I've made a dice roller for any type of dice, and iI would love some feedback on this code. Thank you in advance!

from random import randint

def roll(sides, number_of_dice):
    """Rolls Dice."""
    return [randint(1, sides) for i in range(num_of_dice)]

prompt = """
Would you like to roll the same combination of dice {}? 
Please type 'yes', 'no', or 'quit'
"""

# Main Program

name = raw_input("\nPlease tell me your name > ")

print """
Hello {} and welcome to an RPG Dice Roller by Ray Weiss.
Please type quit when prompted to exit or use CNTRL-C. 
Thanks to everyone at Stack Overflow etc. for the help. 
""".format(name)

sides = input("\nHow many sides do you want on your dice? > ")
num_of_dice = input("\nHow many {} sided dice do you want to roll? >".format(sides))
results = roll(sides, num_of_dice)
print results

roll_again = raw_input(prompt.format(name))

while True:
    
    if roll_again == "yes":
        results = roll(sides, num_of_dice)
        print results
        roll_again = raw_input(prompt.format(name))

    if roll_again == "no": 
        sides = input("How many sides do you want on your dice? > ")
        num_of_dice = input("\nHow many {} sided dice do you want to roll? >".format(sides))
        results = roll(sides, num_of_dice)
        print results
        roll_again = raw_input(prompt.format(name))
    
    if roll_again == "quit":
        print """
Thank you {} for using this RPG Dice Roller by Ray Weiss! Goodbye!
        """.format(name)
        break

This is sort of a follow up to my post yesterday Im a relative newbie to python and before i made a d20 dice roller for rpgs, now i've made a dice roller for any type of dice, and i would love some feedback on this code. Thank you in advance!

from random import randint

def roll(sides, number_of_dice):
    """Rolls Dice."""
    return [randint(1, sides) for i in range(num_of_dice)]

prompt = """
Would you like to roll the same combination of dice {}? 
Please type 'yes', 'no', or 'quit'
"""

# Main Program

name = raw_input("\nPlease tell me your name > ")

print """
Hello {} and welcome to an RPG Dice Roller by Ray Weiss.
Please type quit when prompted to exit or use CNTRL-C. 
Thanks to everyone at Stack Overflow etc. for the help. 
""".format(name)

sides = input("\nHow many sides do you want on your dice? > ")
num_of_dice = input("\nHow many {} sided dice do you want to roll? >".format(sides))
results = roll(sides, num_of_dice)
print results

roll_again = raw_input(prompt.format(name))

while True:
    
    if roll_again == "yes":
        results = roll(sides, num_of_dice)
        print results
        roll_again = raw_input(prompt.format(name))

    if roll_again == "no": 
        sides = input("How many sides do you want on your dice? > ")
        num_of_dice = input("\nHow many {} sided dice do you want to roll? >".format(sides))
        results = roll(sides, num_of_dice)
        print results
        roll_again = raw_input(prompt.format(name))
    
    if roll_again == "quit":
        print """
Thank you {} for using this RPG Dice Roller by Ray Weiss! Goodbye!
        """.format(name)
        break

This is sort of a follow up to my post yesterday. I'm a relative newbie to Python and before I made a d20 dice roller for RPGs. Now I've made a dice roller for any type of dice, and I would love some feedback on this code.

from random import randint

def roll(sides, number_of_dice):
    """Rolls Dice."""
    return [randint(1, sides) for i in range(num_of_dice)]

prompt = """
Would you like to roll the same combination of dice {}? 
Please type 'yes', 'no', or 'quit'
"""

# Main Program

name = raw_input("\nPlease tell me your name > ")

print """
Hello {} and welcome to an RPG Dice Roller by Ray Weiss.
Please type quit when prompted to exit or use CNTRL-C. 
Thanks to everyone at Stack Overflow etc. for the help. 
""".format(name)

sides = input("\nHow many sides do you want on your dice? > ")
num_of_dice = input("\nHow many {} sided dice do you want to roll? >".format(sides))
results = roll(sides, num_of_dice)
print results

roll_again = raw_input(prompt.format(name))

while True:
    
    if roll_again == "yes":
        results = roll(sides, num_of_dice)
        print results
        roll_again = raw_input(prompt.format(name))

    if roll_again == "no": 
        sides = input("How many sides do you want on your dice? > ")
        num_of_dice = input("\nHow many {} sided dice do you want to roll? >".format(sides))
        results = roll(sides, num_of_dice)
        print results
        roll_again = raw_input(prompt.format(name))
    
    if roll_again == "quit":
        print """
Thank you {} for using this RPG Dice Roller by Ray Weiss! Goodbye!
        """.format(name)
        break
Tweeted twitter.com/#!/StackCodeReview/status/249342692675420160
Found a small bug in my original code, repasted.
Source Link
lerugray
  • 605
  • 7
  • 13
Loading
Source Link
lerugray
  • 605
  • 7
  • 13
Loading