本文介绍了TypeError:/的不支持的操作数类型:"str"和"str"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

name = input('Enter name here:')
pyc = input('enter pyc :')
tpy = input('enter tpy:')
percent = (pyc / tpy) * 100;
print (percent)
input('press enter to quit')

每当我运行此程序时,我都会得到这个

whenever i run this program i get this

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

我该怎么做才能将pyc除以tpy?

what can i do to divide pyc by tpy?

推荐答案

通过将它们转换为整数来代替:

By turning them into integers instead:

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

在python 3中,input()函数返回一个字符串.总是.这是对Python 2的更改; raw_input()函数已重命名为input().

In python 3, the input() function returns a string. Always. This is a change from Python 2; the raw_input() function was renamed to input().

这篇关于TypeError:/的不支持的操作数类型:"str"和"str"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-20 18:51