简体   繁体   English

类型错误:不支持 / 的操作数类型:python 中的“str”和“int”错误

[英]TypeError: unsupported operand type(s) for /: 'str' and 'int' error in python

name = input("Въведете име: ")
Town = input("град: ")
school = input("Училище: ")
age= input("години: ")
hoby = input("Хоби: ")
sport = input("спорт: ")

print ("")
print ("Здравейте, казвам се" + name + " ,аз съм на " + age + "години.")
print ("")
print ("Аз живея в/във" + Town + ". " + "Уча в" + school + ".")
print ("Моето хоби е " + hoby + " ,и спортувам " + sport + ".")
print ("")
print ("Въведете 3 числа за триъгълника")
a = input("Страна А ")
b = input("Страна Б ")
c = input("Страна С ")
hc = int(input("Височината на триъгълника е "))
p = int(a) + int(b) + int(c)
S = int((c * hc) / 2)
print ("Периметъра на триъгълника е: " + int(p) + " ,a лицето е: " + int(S))

this is the code.这是代码。

Error:
Traceback (most recent call last):
  File "C:\Users\B21pa\Desktop\Python\Homework\Homework-3\homework-3.py", line 20, in <module>
    S = int((c * hc) / 2)
TypeError: unsupported operand type(s) for /: 'str' and 'int'

You will need to cast the inputs to int() where you explicitly expect them to be integers.您需要将输入转换为int() ,您明确希望它们是整数。 All input captured from the terminal comes across as string.从终端捕获的所有输入都以字符串形式出现。 Attempting to add strings just concatenates them.尝试添加字符串只是将它们连接起来。 Division is not supported on strings hence this error that / is an invalid operand for type str .字符串不支持除法,因此此错误是/是类型str的无效操作数。

Your code fixed should be:您修复的代码应该是:

name = input("Въведете име: ")
Town = input("град: ")
school = input("Училище: ")
age= input("години: ")
hoby = input("Хоби: ")
sport = input("спорт: ")

print ("")
print ("Здравейте, казвам се" + name + " ,аз съм на " + age + "години.")
print ("")
print ("Аз живея в/във" + Town + ". " + "Уча в" + school + ".")
print ("Моето хоби е " + hoby + " ,и спортувам " + sport + ".")
print ("")
print ("Въведете 3 числа за триъгълника")
a = int(input("Страна А "))
b = int(input("Страна Б "))
c = int(input("Страна С "))
hc = int(input("Височината на триъгълника е "))
p = a+b+c
S = int((c * hc) / 2)
print ("Периметъра на триъгълника е: " + str(p) + " ,a лицето е: " + str(S))

暂无
暂无

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

相关问题 Python错误:TypeError:+:&#39;int&#39;和&#39;str&#39;的不支持的操作数类型 - Python Error: TypeError: unsupported operand type(s) for +: 'int' and 'str' Python Panda错误TypeError:/不支持的操作数类型:“ str”和“ int” - Python Panda Error TypeError: unsupported operand type(s) for /: 'str' and 'int' 类型错误:&lt;&lt;:&#39;str&#39; 和 &#39;int&#39; 的操作数类型不受支持 - TypeError: unsupported operand type(s) for <<: 'str' and 'int' TypeError:-:“ int”和“ str”不支持的操作数类型 - TypeError: unsupported operand type(s) for -: 'int' and 'str' 类型错误:不支持 / 的操作数类型:&#39;str&#39; 和 &#39;int&#39; (2) - TypeError: unsupported operand type(s) for /: 'str' and 'int' (2) TypeError:-:“ str”和“ int”的不受支持的操作数类型 - TypeError: unsupported operand type(s) for -: 'str' and 'int' TypeError:+ =不支持的操作数类型:“ int”和“ str” - TypeError: unsupported operand type(s) for +=: 'int' and 'str' TypeError:-:“ str”和“ int”的不受支持的操作数类型(Python) - TypeError: unsupported operand type(s) for -: 'str' and 'int' (Python) Python 3 TypeError:**或pow()不支持的操作数类型:“ str”和“ int” - Python 3 TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int' TypeError的Python问题:+:&#39;int&#39;和&#39;str&#39;的不支持的操作数类型 - Python problem with TypeError: unsupported operand type(s) for +: 'int' and 'str'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM