I have created a piece of code to save some data generated by my code into a txt file on my pc, however when ever i run the program i receive this error,
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
Im not sure what to do with this and need some help in figuring it out, this is my code;
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 ('
')
for i in Char2:
myFile.write (i)
myFile.write('
')
myFile.close()
I know its something to do with the 'str' definitions but I have been fiddling with it for like 30 mins now (yeah im a new programmer} and still to no avail so if someone could provide me with some help that would be great, thanks a lot
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…