#finding square PROGRAM的区域

时间:2016-01-09 10:21:18

标签: python python-3.x

查找square PROGRAM

的区域
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'

3 个答案:

答案 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)