【问题标题】:#finding the area of square PROGRAM#求正方形PROGRAM的面积
【发布时间】:2016-01-09 18:47:12
【问题描述】:

求正方形 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”类型的非整数

【问题讨论】:

标签: python python-3.x


【解决方案1】:

python中的输入是string类型,你必须把它转换成int

area = int(weight) * int(height)

weight = int(input(---))
height = int(input(---))

【讨论】:

    【解决方案2】:
    Error: can't multiply sequence by non-int of type 'str'
    

    你不能乘以字符串。

    使用int() 函数将您的输入转换为int

    height = int(input("Enter height"))
    

    【讨论】:

      【解决方案3】:

      height 和 width 是 str 类型。将其转换为 int 并尝试。

      area = int(height) * int(width)
      
      print("This is the area of a " + height + " x " + width + " square, %d" %area)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-12-06
        • 1970-01-01
        • 1970-01-01
        • 2014-11-03
        • 2014-05-03
        • 2014-06-03
        相关资源
        最近更新 更多