Python TypeError: unsupported operand type(s) for +: ‘int‘ and ‘str‘

When inputting values ​​for addition operation, such an error was reported

TypeError: Operation not supported on types integer and string

Error analysis: sum=sum+input() is not recognized by the system, resulting in a program error

Solution: Define the typed value and declare it as an integer

that is, sum=sum+int(input())

Results of the:

Example 2:

 

Guess you like

Origin blog.csdn.net/qq_42672770/article/details/131924473