-2
我想知道我是否可以將每個字符的屬性信息寫入文本文件,我將如何能夠做到這一點?每次有人玩遊戲時,記事本文件上的屬性都需要更新。如何將我從python生成的信息寫入文件?
def strength():
dice12 = random.randint(1,12)
dice04 = random.randint(1,4)
strfinalstats = dice12/dice04+10
print ">",strfinalstats,"strength"
def skill():
dice12 = random.randint(1,12)
dice04 = random.randint(1,4)
skfinalstats = dice12/dice04+10
print ">",skfinalstats,"skill!"
def player1():
name1=raw_input("what would you like to call the first player?")
print name1,"has:"
time.sleep(1)
strength()
time.sleep(1)
skill()
def player2():
name2=raw_input("what would you like to call the first player?")
print name2,"has:"
time.sleep(1)
strength()
time.sleep(1)
skill()
def player3():
name3=raw_input("what would you like to call the first player?")
print name3,"has:"
time.sleep(1)
strength()
time.sleep(1)
skill()
你有沒有嘗試過任何東西? – jonrsharpe
有很多「如何將X寫入文件?」關於SO Python的問題。請搜索其中的一個,並遵循適當的答案。 –
[Python保存到文件]的可能重複(http://stackoverflow.com/questions/9536714/python-save-to-file) –