Hello, I am new to programming. I am trying to make a dice game called 10,000. Here is the outline or pseudo code. it kind of works. It will roll and keep score, but sometimes it will roll multiple times.

pick a player player one or player two
player rolls six die
if any of the six die are ones or fives
add those scores to active players score
ones are worth 100 points
fives are worth 50 points
player rolls again minus the die that had a value of one or five
example: roll 6 die-values:1,3,2,5,6,4 two of the die hava a value of 1 or 5 so the next roll will
be with 4 die
repeat if with 4 die
if any of the 4 die are ones or fives
add those scores to active players score
ones are worth 100 points
fives are worth 50 points
if any of the rounds does not have a one or five, the turn passes to the next player
Example game:

Player one rolls six die: 1,1,4,6,3,5
player one gets 250 points
player decides if they want to keep the points or risk rolling three die and not getting any ones or fives.
If no ones or fives, turn lost.
player one rolls three die:2,1,4
player one gets 100 points added to score for a total of 350 points
player decides if they want to keep the points or risk rolling two die and not getting any ones or fives.
player one rolls two die and looses points and turn.2,6
player two rolls six die: 5,6,3,3,1,4
player two gets 150 points
player decides if they want to keep the points or risk rolling four die and not getting any ones or fives.
If no ones or fives, turn lost
player rolls four die:1,1,3,5
player two gets 250 added to score for a total of 400 points
player two opts to pass turn and keep points
if a player continues to roll and make ones or fives until the die remaining are 0, player starts over with 6 die.
the game ends when a player reaches 10,000 points

Here is what I have Frankensteined so far:

import random
def rollDice():
    roll = []
    roll.append(random.randint(1, 6))
    roll.append(random.randint(1, 6))
    roll.append(random.randint(1, 6))
    roll.append(random.randint(1, 6))
    roll.append(random.randint(1, 6))
    roll.append(random.randint(1, 6))
    print "%d,%d,%d,%d,%d,%d" %(roll[0], roll[1], roll[2],roll[3], roll[4], roll[5])
    return roll
score=0
response="no"
response=raw_input("\nWould you like a roll?\n")
while response!="no":
    if response=="yes"or response=="y"or response=="":
        roll=rollDice()
    else:
        print "That is not a valid response"
        response=raw_input("\nWould you like a roll?\n")
    if roll[0]==1:
        score+=100
        print "You got",score,"points"
    else:
        ""
    if roll[1]==1:
        score+=100
        print "You got",score,"points"
    else:
        ""
    if roll[2]==1:
        score+=100
        print "You got",score,"points"
    else:
        ""
    if roll[3]==1:
        score+=100
        print "You got",score,"points"
    else:
        ""
    if roll[4]==1:
        score+=100
        print "You got",score,"points"
    else:
        ""
    if roll[5]==1:
        score+=100
        print "You got",score,"points"
    else:
        ""
    if roll[0]==5:
        score+=50
        print "You got",score,"points"
    else:
        ""
    if roll[1]==5:
        score+=50
        print "You got",score,"points"
    else:
        ""
    if roll[2]==5:
        score+=50
        print "You got",score,"points"
    else:
        ""
    if roll[3]==5:
        score+=50
        print "You got",score,"points"
    else:
        ""
    if roll[4]==5:
        score+=1
        print "You got",score,"points"
    else:
        ""
    if roll[5]==5:
        score+=50
        print "You got",score,"points"
    else:
        print "Your total score for this round is",score
        response=raw_input("\nPress enter to roll again or 'no' to exit the program?")

raw_input=("\enter to exit")

Thanks for your time.

From looking at your code i have shorten it down.
You have to many repating statement,that is not so good in programming.
Have not read all rule off game,that you have to work on.

from random import randint

def rollDice():
    return [randint(1, 6) for r in range(6)]

def user_input():
    while True:
        response = raw_input("\nWould you like a roll?\n").lower()
        if response in ['y','yes','']:
            dice = rollDice()
            return dice
        else:
            print "That is not a valid response,try again"

if __name__ == '__main__':
    roll = user_input()
    print roll
    score = 0
    for i in roll:
        if i == 1:
            score+=100
        if i == 5:
            score+=50
    print 'Your total score for this round is %s' % score

Edited 6 Years Ago by snippsat: n/a

Well, that is indeed a monster... Here are some things to think about:

  • function rollDice can be simplified two ways:
    1. you can just call random.randint(1,6) directly inside the square brackets. No need for the multiple appends
    2. you can just print(roll) for a sufficiently pretty output, though yours works.
  • You should create a function def value_of(roll): ... that uses a for loop to to sum up the value of the roll. Call that in your loop instead of doing it inline.
  • You should create a function def ask_roll():... that asks if you want to continue, copes if the user strikes <return>, changes the value to lower case and returns the first letter; and which keeps asking until you give a legal response of 'y', 'n' or <return>. This puts all the asking and error handling in one place
  • Your loop doesn't seem to quit if the sum is 0. It should.
  • You should get in the habit of providing doc strings for your functions (see example below)

Just FYI, my code to do this is under 50 lines (without doc strings)
example of doc strings:

def nothing():
    """This function is documented to do nothing with no side effects"""
    return
This article has been dead for over six months. Start a new discussion instead.