print("Finding the area of a square")
height = input("Please enter the height of your square\n")
width = input("Please enter the width of your square\n")
area = height * width
print("This is the area of a " + height + " x " + width + " square, " + area)
错误:不能将序列乘以非类型' str'
答案 0 :(得分:0)
python中的输入是字符串类型,您必须将其转换为 int :
area = int(weight) * int(height)
或
weight = int(input(---))
height = int(input(---))
答案 1 :(得分:0)
Error: can't multiply sequence by non-int of type 'str'
你不能乘以字符串。
使用int
函数将输入转换为int()
。
height = int(input("Enter height"))
答案 2 :(得分:0)
高度和宽度是str类型。将其转换为int并尝试。
area = int(height) * int(width)
print("This is the area of a " + height + " x " + width + " square, %d" %area)