TypeError:get_stats()只取1个参数(给定0)

时间:2015-01-03 13:50:20

标签: class python-2.7

尝试一个dnd角色创建者:继续得到:TypeError:get_stats()只取一个参数(给定0)。我不知道如何给shell提供它想要的东西。

下面是代码:

import random

class Character(object):

       def __init__(self,name):

         self.name = raw_input('name')

        #  Attributes for Pathfinder
        def get_stats(self):
            stats = []
            count = 0
            while count < 6:
                roll = []
                roll = [random.randint(1,6) for x in range(4)]   
                roll = sorted(roll)
                del(roll[0])
                sum = 0
                for x in roll:
                    sum += x
                stats.append(sum)
                count += 1


            print stats
            return stats

        stats = get_stats()
        ste = stats[0]
        con = stats[1]
        dex = stats[2]
        inte = stats[3]
        wis = stats[4]
        cha = stats[5]

        #Modifiers
        stemod = (ste - 10)/2
        dexmod = (dex - 10)/2
        conmod = (con - 10)/2
        intemod = (inte - 10)/2
        wismod = (wis - 10)/2
        chamod = (cha - 10)/2 

        #Bios
        #Sex

        sex = random.randint(1,2)
        if sex == 1:
            sex = "male"
        else:
            sex = "female"

        #Races and size
        #list_of_races
        x = random.randint(1,7)
        if x == 1:
            race = 'drawf'
            size = 'med'
            con += 2
            wis += 2
            cha -= 2
        elif x == 2:
            race = 'elf'
            size = 'med'
            dex += 2
            inte += 2
            con -= 2
        elif x == 3:
            race = 'human'
            size = 'med'
            bonus = random.randint(1,6)
            if bonus == 1:
                ste += 2
            elif bonus == 2:
                con += 2
            elif bonus == 3:
                dex += 2
            elif bonus == 4:
                inte += 2
            elif bonus == 5:
                wis += 2
            elif bonus == 6:
                cha += 2
        elif x == 4:
            race = 'halfling'
            size = 'small'
            dex += 2
            cha += 2
            ste -= 2
        elif x == 5:
            race = 'gnome'
            size = 'small'
            con += 2
            cha += 2
            ste -= 2
        elif x == 6:
            race = 'half-elf'
            size = 'med'
            bonus = random.randint(1,6)
            if bonus == 1:
                ste += 2
            elif bonus == 2:
                con += 2
            elif bonus == 3:
                dex += 2
            elif bonus == 4:
                inte += 2
            elif bonus == 5:
                wis += 2
            elif bonus == 6:
                cha += 2
        elif x == 7:
            race = 'half-orc'
            size = 'med'
            bonus = random.randint(1,6)
            if bonus == 1:
                ste += 2
            elif bonus == 2:
                con += 2
            elif bonus == 3:
                dex += 2
            elif bonus == 4:
                inte += 2
            elif bonus == 5:
                wis += 2
            elif bonus == 6:
                cha += 2

        #Size pelenties




        #Classes
        # List of classes(Fighter,Ranger,Wizard,Cleric)
        c = random.randint(1,4)
        playclass = ''
        while playclass == '':
            if c == 1 and ste > 10:
                playclass = 'Fighter'
                hp = 10 + conmod
                bab = 1
                fort_save = 2 + conmod
                reflex_save = 0 + dexmod
                will_save = 0 + wismod
            elif c == 2:
                playclass = 'Ranger'
                hp = 10 + conmod
                bab = 1
                fort_save = 2 + conmod
                reflex_save = 2 + dexmod
                will_save = 0 + wismod
            elif c == 3 and inte > 10:
                playclass = 'Wizard'
                hp = 6 + conmod
                bab = 0
                fort_save = 0 + conmod
                reflex_save = 0 + dexmod
                will_save = 2 + wismod
            elif c == 4 and wis > 10:
                playclass = 'Cleric'
                hp = 8 + conmod
                bab = 0
                fort_save = 2 + conmod
                reflex_save = 0 + dexmod
                will_save = 2 + wismod
            else:
                c = random.randint(1,3)

        #AC
        ac = 10 + dexmod
        if size == 'small':
            ac += 1


        print sex
        print size +" "+race
        print 'strenght : ' + str(ste)
        print 'constitution : ' + str(con)
        print 'dexterity : ' + str(dex)
        print 'intelligence : ' + str(inte)
        print 'wisdom : ' + str(wis)
        print 'charisma : ' + str(cha)
        print playclass
        print 'HP:' + str(hp)
        print 'AC:' + str(ac)
        print 'BAB:' + str(bab)
        print 'Fort:' + str(fort_save)
        print 'Will:' + str(will_save)
        print 'Reflex:' + str(reflex_save)

1 个答案:

答案 0 :(得分:0)

get_stats()功能中,您已放置self。但是为了填补这一行中的范例:

stats = get_stats()

你应该在你的parantheses中放置None以防止错误。所以该行看起来像:

stats = get_stats(None)

为什么添加None?这意味着除self以外的parantheses中的内容数量为0或None。我希望这可以帮助你!