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