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

后端 未结 4 1673
说谎
说谎 2020-11-27 21:44
name = input(\'Enter name here:\')
pyc = input(\'enter pyc :\')
tpy = input(\'enter tpy:\')
percent = (pyc / tpy) * 100;
print (percent)
input(\'press enter to quit\         


        
4条回答
  •  时光说笑
    2020-11-27 22:26

    The first thing you should do is learn to read error messages. What does it tell you -- that you can't use two strings with the divide operator.

    So, ask yourself why they are strings and how do you make them not-strings. They are strings because all input is done via strings. And the way to make then not-strings is to convert them.

    One way to convert a string to an integer is to use the int function. For example:

    percent = (int(pyc) / int(tpy)) * 100
    

提交回复
热议问题