プログラムをより効率的にしたい、「for ループ」を使用することを考えていましたが、コードに実装する方法がわかりません。また、ファイルへの書き込み部分が非常に長いので、短くしたいです。
import random
def character_attributes():
initial_value = 10
character1_strength = initial_value + (random.randint(1,12) // random.randint(1,4))
character1_skill = initial_value + (random.randint(1,12) // random.randint(1,4))
character2_strength = initial_value + (random.randint(1,12) // random.randint(1,4))
character2_skill = initial_value + (random.randint(1,12) // random.randint(1,4))
print("Character 1 now has a strength attribute of {0}".format(character1_strength))
print("Character 1 now has a skill attribute of {0}".format(character1_skill))
print("Character 2 now has a strength attribute of {0}".format(character2_strength))
print("Character 2 now has a skill attribute of {0}".format (character2_skill))
myfile = open('character_attribute_data.txt', 'w')
myfile.writelines('Character 1 has a strength attribute of : ')
myfile.writelines(str(character1_strength))
myfile.writelines('\n')
myfile.writelines('Character 1 has a skill attribute of: ')
myfile.writelines(str(character1_skill))
myfile.writelines('\n')
myfile.writelines('Character 2 has a strength attribute of : ')
myfile.writelines(str(character2_strength))
myfile.writelines('\n')
myfile.writelines('Character 2 has a strength attribute of : ')
myfile.writelines(str(character2_skill))
myfile.close()