python - 我不断收到类型错误,不知道为什么
问题描述
def printWord(a,b):
a= raw_input ("What would you like me to say?")
b= raw_input ("How many times would you like me to say it?")
int(float(b))
for i in range(b):
print a
这段代码不断给我这个错误:
line 10, in printWord
for i in range(b):
TypeError: range() integer end argument expected, got str.
解决方案
你对这条线有正确的想法:
int(float(b))
但这并没有就地改变 b 。你必须保留结果。用这个:
b = int(float(b))
推荐阅读
- react-native - 如何使用 expo FileSystem 获取文件扩展名?
- bash - 当它们来自命令行时,我们如何 egrep 特殊字符?
- javascript - 如何从javascript中提取字符串
- python - python 在初始化超过 31 个元素时出现问题
- c - 检查是否设置或清除了多个位
- ios - 自定义嵌套对象的 Swift 编码技术?
- python - Django - csv.reader 和 save()/update
- python - 从图像中去除噪声,使其准备好使用 python 进行 tesseract ocr 并打开 cv
- java - startActivity :哪种方法更好,为什么?
- python - Ubuntu中的Python多处理内存泄漏,但在Windows中没有