我已經創建了一段代碼,當過我運行程序我收到此錯誤由我的代碼生成的一些數據,但保存到一個txt文件在我的電腦,問題與保存到一個txt在Python 3.3.2
Traceback (most recent call last):
File "E:\CA2 solution.py", line 14, in <module>
char1[1]="Strength now " +strh1
TypeError: Can't convert 'int' object to str implicitly
林不知道該怎麼做,需要一些幫助,計算出來,這是我的代碼;
import random
char1=str(input('Please enter a name for character 1: '))
strh1=((random.randrange(1,4))//(random.randrange(1,12))+10)
skl1=((random.randrange(1,4))//(random.randrange(1,12))+10)
print ('%s has a strength value of %s and a skill value of %s)'%(char1,strh1,skl1))
char2=str(input('Please enter a name for character 2: '))
strh2=((random.randrange(1,4))//(random.randrange(1,12))+10)
skl2=((random.randrange(1,4))//(random.randrange(1,12))+10)
print('%s has a strength value of %s and a skill value of %s'%(char1,strh1,skl1))
char1[1]="Strength now " +strh1
char1[2]="Skill now " +skl1
char2[1]="Strength now " +strh2
print()
char2[2]="Skill now " +skl1
print()
myFile=open('CharAttValues.txt','wt')
for i in Char1:
myFile.write (i)
myFile.write ('\n')
for i in Char2:
myFile.write (i)
myFile.write('\n')
myFile.close()
我知道它的東西做的「STR」的定義,但我一直在用它擺弄像現在30分鐘(是的,我是一個新的程序員},仍然無濟於事,所以如果有人能爲我提供一些幫助,將是巨大的,非常感謝