0
如果我运行此代码,Python和空闲都会退出。我使用Python 3.2,并且在改变代码之后可能会出现一些错误。运行我的脚本时发生意外的Python(和空闲)崩溃
我的目标是创建一个文件,将代码复制到一个单独的文件中供以后使用。就在最近,Python 2.7崩溃了,现在Python 3.2正在发生这种情况。在计算机上试用此代码,看看会发生什么。
请给我一些提示,因为这很烦人。
def creating():
print ('You have a total of 70 points to spend on str(strength), chr(charisma), dex(dexterity), int(intelligence), con(constitution).\nIf you put in a greater amount it will restart the character creation process; and if you put a smaller amount then you will be told you can add more.\nYou may also only have a limit of 18 on one attribute or you will restart the stat creation process.')
global st
global ch
global de
global inte
global con
#It gives me an error for the stuff above if it doesn't crash
st = (input('str:'))
ch = (input('chr:'))
de = (input('dex:'))
inte = (input('int:'))
con = (input('con:'))
global scores
score = st+ch+de+inte+inte+con
global scores
scores = 70-score
#If I have the globals above it crashes and if I take it away it works.
def bunnyoperation():
rew = open('C:/Python32/charactersave.py','w')
rew.write(('st=')+str(st))
rew.write(('\nch=')+str(ch))
rew.write(('\nde=')+str(de))
rew.write(('\ninte=')+str(inte))
rew.write(('\ncon=')+str(con))
rew.close()
def scorecor():
if score == 70 and st<19 and ch<19 and de<19 and inte<19 and con<19:
bunnyoperation()
elif score>70:
print ('you have a total of too many points.')
creating()
elif score<70:
print ('You still have ')+str(scores)+(' points left')
creating()
elif st or ch or de or inte or con>18:
print ('You set one of your stats as something over 18.\nYou will have to restart.')
creating()
else:
creating()
creating()
我认为你需要回顾一下你正在努力做,并且更加明确。你的代码非常混乱(为什么所有这些全局变量?)。在我的系统上,它不会崩溃python或闲置(我得到一个'NameError',因为st,ch等没有定义:事实上它们不是......) – Salem 2013-05-04 19:40:07
为什么你使用这么多全局变量,为什么你无论如何,如果他们是全球性的,那么在方法中声明它们? – MentholBonbon 2013-05-04 20:09:02
我得到这个错误:'NameError:全球名'st'没有定义' – User 2013-05-04 20:21:18