TypeError: can't multiply sequence by non-int of type 'str'

后端 未结 3 1553
醉话见心
醉话见心 2020-12-11 23:57
>>> 
Enter muzzle velocity (m/2): 60
Enter angle (degrees): 45
Traceback (most recent call last):
  File \"F:/Python31/Lib/idlelib/test\", line 9, in 

        
3条回答
  •  自闭症患者
    2020-12-12 00:16

    >>> '60' * '60'
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: can't multiply sequence by non-int of type 'str'
    

    You are trying to multiply two strings together. You must convert the string input from the user to a number using int() or float().

    Also, I'm not sure what you're doing with decimal; it looks like you're trying to call the module (the type is in the module, decimal.Decimal) but there's not much point in converting to a Decimal after doing some floating point math and then converting back to a float.

    In the future, post the code that causes the problem (and keep the interaction and traceback). But first try and shrink the code as much as possible while making sure it still causes the error. This is an important step in debugging.

提交回复
热议问题