我收到错误“必须是str,而不是builtin_function_or_method”

时间:2017-05-23 16:09:07

标签: python

我有这段代码

 strMph = ""
 numberplate = ""
 print("Today we are going to determine how fast vehicles are going.")
 while numberplate != "-1":
 numberplate = str(input("Enter a numberplate or enter -1 to stop and show all vehicles that went over the speed limit "))
if numberplate != "-1":
    name = str(input("Please enter the name of the owner of that car "))
    adress = str(input("Please enter the adress of the owner of that car "))
    distance = 30
    time = float(input("How long did that take in seconds to travel between the two speed cameras that are 30 meters apart "))
    speed = distance / time
    mps = str(speed)
    strMph = speed * 2.23
    mph = str(strMph)
    print("That is a speed of " +mps +" meters per second or  " + mph+ " miles per hour ")
    if strMph > 40:
            valid = False
            if (numberplate.count(numberplate.isalpha) == 5):
                if (numberplate.count(int) == 2):
                    valid = True
            else:
                valid == False

            if valid == True:
                print("This numberplate is  a standard numberplate")
                file = open("IllegalPlates.txt", "a")
                file.write("Numberplate")
                file.write(numberplate)
                file.write("Is a standard numberplate")
                file.write("and belongs to")
                file.write(name)
                file.write("who lives at")
                file.write(adress)
                file.write(",")
                file.close()
            else:
                print("This numberplate is not a standard numberplate")
                file = open("IllegalPlates.txt", "a")
                file.write("Numberplate")
                file.write(numberplate)
                file.write("Is not a standard numberplate")
                file.write("and belongs to")
                file.write(name)
                file.write("who lives at")
                file.write(adress)
                file.write(",")
                file.close()
else:
    print ("The cars that will be reciving a ticket are ")
    file = open("IllegalPlates.txt", "r")
    print (file.readlines())
    f = open("IllegalPlates.txt", 'w')
    break

我收到此错误消息

must be str, not builtin_function_or_method

当我输入列表并且使用验证号码牌的方法干扰时,不会起作用的位。有人可以帮忙吗?此外,我在python 3.6.0上,我知道代码是凌乱的我有点新的在这。缩进可能对此不好,但它不在我的代码中。建议会很好。

2 个答案:

答案 0 :(得分:0)

你想在这做什么?代码构建为接受输入 - 一个接一个。你是说你想一次性输入多个值吗?

答案 1 :(得分:0)

此行是生成该错误的行:

if (numberplate.count(numberplate.isalpha) == 5)

isalpha是一个函数,因此您应该将()放在其后面。但是,它仍然没有多大意义,因为它返回一个布尔值。 这个也很奇怪:

if (numberplate.count(int) == 2):

你到底想要完成什么?