这个程序不断崩溃,我无法解决为什么?
g = raw_input("Any other items enter the price: $")
if (g.isalpha()):
g = 0.0
if (g.isdigit()):
g = g
else:
g = 0.0
Pat=(raw_input('And how many of this item:'))
if (Pat.isalpha()):
Pat = 0.0
if (Pat.isdigit()):
Pat = Pat
else:
Pat = 0.0
g_ = (Pat * g)
Total = (a_ + b_ + c_ + d_ + e_ + f_ + g_)
print'Total: $',Total, '''
它使返回错误:这个程序不断崩溃,我无法解决为什么?
TypeError: can't multiply sequence by non-int of type 'str'
此行只是分配一个字符串返回
if (Pat.isdigit()):
Pat = Pat
我假设你的意思
if (Pat.isdigit()):
Pat = int(Pat)
'g'也一样。 'if(g.isdigit()):g = g'将'g'作为'str'返回。 –
TypeError:不支持的操作数类型为+:'float'和'str' – GAVDADDY
如果您期望对它们进行算术运算,则应该将您的变量转换为“float”和“int”。我建议你找到一个好的Python文本并阅读“数据类型” – CoryKramer
的可能的复制[为什么我获取TypeError:不能通过类型为'float'的非int类型乘以序列?](https://stackoverflow.com/questions/485789/为什么 - 我 - 得到 - 类型错误 - 错误 - 乘法 - 非整型 - 浮点型) –