Python typeerrorfloatrequiredline.20

Python typeerrorfloatrequiredline.20,python,arrays,Python,Arrays,我今天心情不好。我已将您的代码修复为所需的功能。:) 主要是,您有多个错误。 1) 您的elifs的缩进错误。 2) 参数传递错误,area=areaOfcircle(x) 3) areaOfsquare(“正方形的长度是多少?”)正在尝试传递字符串并计算字符串。 4) 在设计方面,在要求测量之前,您应该先要求用户输入形状。 5) if shape==“Triangle”或“Triangle”:应更改为if shape.lower()==“Triangle”: #Python program w

我今天心情不好。我已将您的代码修复为所需的功能。:)
主要是,您有多个错误。
1) 您的
elif
s的缩进错误。
2) 参数传递错误,
area=areaOfcircle(x)

3)
areaOfsquare(“正方形的长度是多少?”)
正在尝试传递字符串并计算字符串。
4) 在设计方面,在要求测量之前,您应该先要求用户输入形状。
5)
if shape==“Triangle”或“Triangle”:
应更改为
if shape.lower()==“Triangle”:

#Python program when involved with maths
import math

def areaOfcircle(x):
#Calculate the area
    area=(math.pi)*math.pow(x,2)
    print(area,"is the area of your circle")
#Input used to find x
areaOfcircle(int(input("What is the radius of your circle?")))

def areaOftriangle(b,h):
    area=(b+h)/2
    print(area,"is the area of your triangle")

areaOftriangle(int(input("What is the base of your triangle")),int(input("What is the hight of your triangle")))

def areaOfsquare(x):
    area=math.pow(x,2)
    print(area,"is the area of your square")

areaOfsquare("What is the length of your square?")

flag="f"
while flag=="f":
    shape=input("Which of the following shapes, Circle, Triangle or Square do you want to calculate the area of: ")
    if shape=="Triangle" or "triangle":
        area=areaOftriangle
        print(area)

elif shape=="Square" or "square":
    area=areaOfsqaure
    print(area)

elif shape=="Circle" or "circle":
    area=areaOfcircle(x)
    print(area)

读取正方形的
区域时出现错误。。。您需要请求输入,但您没有这样做。有问题吗?如果您只是将
标志
声明与您自己的声明进行比较,除了让您进入无限循环之外,它还能为您带来什么?我知道提问者这样做了,但你还没有完全进入理智的状态。我可能遗漏了什么。@herk
标志
声明并不重要,因为它是一个
True
-y值。我不知道为什么提问者不想在True:
循环时执行
。我只是修复了代码中的所有bug,以实现所需的功能。无限循环被
break
import math

def areaOfcircle(x):
    area=(math.pi)*math.pow(x,2)
    print(area,"is the area of your circle")

def areaOftriangle(b,h):
    area=(b+h)/2
    print(area,"is the area of your triangle")

def areaOfsquare(x):
    area=math.pow(x,2)
    print(area,"is the area of your square")



flag="f"
while flag=="f":
    shape=input("Which of the following shapes, Circle, Triangle or Square do you want to calculate the area of: ")
    if shape.lower() == "triangle":
        areaOftriangle(float(input("What is the base of your triangle? ")),float(input("What is the height of your triangle? ")))
        break

    elif shape.lower() == "square":
        areaOfsquare(float(input("What is the length of your square? ")))
        break

    elif shape.lower() == "circle":
        area=areaOfcircle(float(input("What is the radius of your circle? ")))
        break
    else:
        print('No such shape, please try again')