python – TypeError:/:’str’和’str’的不支持的操作数类型
发布时间:2020-12-20 10:33:53 所属栏目:Python 来源:网络整理
导读:name = input('Enter name here:')pyc = input('enter pyc :')tpy = input('enter tpy:')percent = (pyc / tpy) * 100;print (percent)input('press enter to quit') 每当我运行这个程序,我得到这个 TypeError: unsupported operand type(s) for /: 'str' an
name = input('Enter name here:') pyc = input('enter pyc :') tpy = input('enter tpy:') percent = (pyc / tpy) * 100; print (percent) input('press enter to quit') 每当我运行这个程序,我得到这个 TypeError: unsupported operand type(s) for /: 'str' and 'str' 我该怎么做才能将pyc除以tpy? 解决方法
通过将它们变成整数:
percent = (int(pyc) / int(tpy)) * 100; 在python 3中,input()函数返回一个字符串.总是.这是Python 2的变化; raw_input()函数被重命名为input(). (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |