import random
import time
x = 1
def clear():
print "\n" * 100
while x == 1:
number1 = random.randrange(1,5)
number2 = random.randrange(1,13)
strength = number2/number1+10
number3 = random.randrange(1,5)
number4 = random.randrange(1,13)
skill = number4/number3+10
clear()
print 'Hello and Welcome to the Character Charactaristics Machine'
time.sleep(1)
clear()
qname = raw_input("What is your Character's name?:")
time.sleep(1)
clear()
print "We will now determine", qname,"'s Charactaristics"
time.sleep(0.5)
print 'Calculating...'
time.sleep(0.5)
print 'Calculating...'
time.sleep(0.5)
print 'Calculating...'
time.sleep(0.5)
character = (qname,"'s skill level is",skill,"and strength level is" ,strength,)
print character
x = 2
characterdata = open("test.txt", "w")
characterdata.write(character)
characterdata.close
我正在制作一个程序,您可以在其中输入角色名称,然后生成其强度和技能水平。我想要它,以便将角色的名称和技能/强度级别保存在某种数据库中。我试图让字符串“字符”(字符的详细信息)显示在 test.txt 文档中,但出现此错误:
Traceback (most recent call last):
File "C:\Users\George\Documents\School Work\Characterisitcs of character the code.py", line 34, in <module>
characterdata.write(character)
TypeError: expected a character buffer object
有帮助吗,谢谢