简体   繁体   English

如何修复错误无法划分 int 和 str,我无法修复它

[英]how to fix error cant divide int and str, i cant fix it

print("===DIVIDING CALCULATOR===\n")

inputAngka = int(input("Insert the number : "))
inputPembagi = input("Insert the dividers : ")

if inputPembagi.isdigit:
    print("The result is",inputAngka/inputPembagi)
elif inputPembagi == 0:
    print("Can't divide a number by 0!")
else:
    print("Inputted data should be in integer!")

i want to make this code run i cant divide between first input and second input我想让这段代码运行我不能在第一个输入和第二个输入之间划分

The problem is that the input function returns a string, even if you enter a number.问题是输入函数返回一个字符串,即使您输入一个数字。 You have to convert to an integer or float.您必须转换为整数浮点数。

number = input("Enter a number")
# Let's say I input 10. 
number = int(number) # Or float(number)

Now, you can divide.现在,你可以分开了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法修复 Python 错误 AttributeError: 'int' object 没有属性 'get' - Cant fix Python error AttributeError: 'int' object has no attribute 'get' 我无法使用 pip install 获得工作室代码来安装 dotenv。 错误找不到模块,请问我该如何解决? - I cant get studio code to install dotenv with pip install. Error cant find module, how do I fix it please? 我的乌龟代码有一个错误,我似乎无法解决 - My turtle code has an error i cant seem to fix at the end of it 属性错误。 可能很容易修复,但我找不到解决方案 - Attribute error. Probably easy to fix but i cant find solution 无法弄清楚如何解决此问题。 Python Selenium Chromedriver错误 - Cant figure out how to fix this. Python Selenium Chromedriver Error 'str' object 没有属性 'text'。 似乎无法修复它 - 'str' object has no attribute 'text'. Cant seem to be able to fix it 如何在python 3.3中修复此错误? TypeError:不可排序的类型:str()&lt;int() - how do I fix this error in python 3.3? TypeError: unorderable types: str() < int() 无法修复 DtypeWarning - Cant Fix DtypeWarning 无法修复:AttributeError:startswith - Cant fix: AttributeError: startswith 我似乎无法在我的代码中修复这些错误 - I cant seem to fix these erros in my code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM