TypeError Full code #矩形输入
print("~" * 60)
print("~" * 60)
lengthOne = str(int(input("Enter the Length of Rectangle #01 = ")));
widthOne = str(int(input("Enter the Width of Rectangle #01 = ")));
areaRecOne = (lengthOne * widthOne)
print("~" * 60)
lengthTwo = str(input("Enter the Length of Rectangle #02 = "));
widthTwo = str(input("Enter the Width of Rectangle #02 = "));
#Output of Rectangles
print("~" * 60)
print("~" * 60)
print("Length of Rectangle #01 = " + lengthOne + " SQ Inches");
print("Width of Rectangle #01 = " + widthOne + " SQ Inches");
print("Area of Rectangle #01 = " + areaRecOne + " SQ Inches");
print("~" * 60)
print("Length of Rectangle #02 = " + lengthTwo + " SQ Inches");
print("Width of Rectangle #02 = " + widthTwo + " SQ Inches");
print("~" * 60)
print("~" * 60)
#Calculation which Rectangle is greater
我刚开始上COP1000课,我一直在解决这个不断出现的问题。我尝试了我所学到的一切,但没有结果。你知道吗
我需要的是让代码计算矩形的面积并统计哪个矩形更大
但每次乘法都是这么说的
areaRecOne = (lengthOne * widthOne)
TypeError: can't multiply sequence by non-int of type 'str'
提前谢谢!你知道吗
看起来您正在将输入转换为
int
(这很好),然后再转换回str
(这就是问题所在)。你知道吗试试看
另外,我建议在Python中使用
snake_case
;它更规范。你知道吗编辑:
这里有一个简化版本的程序,供您根据您的实现。你知道吗
相关问题 更多 >
编程相关推荐