![](/img/trans.png)
[英]TypeError: unsupported operand type(s) for /: 'tuple' and 'int'
[英]TypeError: unsupported operand type(s) for %: 'tuple' and 'int'
我在我的个人项目中遇到了另一个问题,该问题引起了不满。 如果解决方案很明显,请原谅我,我对python很陌生。
问题是当我运行这个程序时,我收到一个错误消息
类型错误:% 不支持的操作数类型:'tuple' 和 'int'
我不确定如何解决这个问题,因为关于这个问题的其他查询是关于我觉得难以理解的代码,因此无法理解解决方案。 任何帮助,将不胜感激。 谢谢你。
def totalcalc(total1,total2):
if total1 % 2 == 0:
total1 = total1 + 10
else:
total1 = total1 - 5
if total2 % 2 == 0:
total2 = total2 + 10
else:
total2 = total2 - 5
return total1,total2
total1 = 0
total2 = 0
total1 = int(input("num1: "))
total2 = int(input("num2: "))
total1 = totalcalc(total1,total2)
total2 = totalcalc(total1,total2)
print(total1)
print(total2)
你应该试试
def totalcalc(total1,total2):
if total1 % 2 == 0:
total1 = total1 + 10
else:
total1 = total1 - 5
if total2 % 2 == 0:
total2 = total2 + 10
else:
total2 = total2 - 5
return total1,total2
total1 = 0
total2 = 0
total1 = int(input("num1: "))
total2 = int(input("num2: "))
FinalAnswer = totalcalc(total1,total2)
print("Total1:{}".format(FinalAnswer[0]))
print("Total1:{}".format(FinalAnswer[1]))
Aur 只是尝试多级变量赋值,如@Chris 所说
total1, total2 = totalcalc(total1,total2)
print(total1)
print(total2)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.