TypeError: get_stats() takes exactly 1 argument (0 given)
TypeError: get_stats() takes exactly 1 argument (0 given)
尝试使用 dnd 字符创建器:不断获取 a:TypeError:get_stats() 恰好需要 1 个参数(给定 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)
在您的 get_stats()
函数中,您输入了 self
。但要填写行中的括号:
stats = get_stats()
您应该将 None
放在您的括号中以防止错误。所以这条线看起来像:
stats = get_stats(None)
为什么添加None
?这意味着除了 self
之外的括号中的东西的数量是 0 或 None
。希望对您有所帮助!
尝试使用 dnd 字符创建器:不断获取 a:TypeError:get_stats() 恰好需要 1 个参数(给定 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)
在您的 get_stats()
函数中,您输入了 self
。但要填写行中的括号:
stats = get_stats()
您应该将 None
放在您的括号中以防止错误。所以这条线看起来像:
stats = get_stats(None)
为什么添加None
?这意味着除了 self
之外的括号中的东西的数量是 0 或 None
。希望对您有所帮助!