TypeError: unsupported operand type(s) for +: 'float' and 'str'

后端 未结 1 1742
后悔当初
后悔当初 2021-01-25 02:35

Why is my code not working and what does this error mean?

import random
initial_val = str(10)
attr_c1_stre = (\"Character 1\'s Strength: \",str(random.randint(1,         


        
1条回答
  •  无人及你
    2021-01-25 03:14

    initial_val is a string:

    initial_val = str(10)
    

    You are trying to add it to a floating point value:

    random.randint(1,12)/random.randint(1,4) + initial_val
    

    initial_val should not be a string; leave it as an integer instead:

    initial_val = 10
    

    0 讨论(0)
提交回复
热议问题