>

이 번호는 라이센스, 번호판을 스캔하고 속도가 빠른지 여부를 확인하고 모든 정보를 output.txt라는 텍스트 문서에 쓰는 ANPR 카메라 용 코드입니다. 그것은 모두 한 부분이 아닌 다른 부분에서 작동합니다. 아래를 참조하십시오. 또한 오류 코드가 나타나지 않습니다

#Imports
import time
import random
#Gets the number plate
np=input()
#Sets the parts of the license plate
twoletters=np[0:2]
twonumbers=np[2:4]
threeletters=np[4:7]
#Sensors
sensor1=0
sensor2=random.uniform(0.25, 0.4)
sensor2=round(sensor2, 1)
#Variables
twoletterstf=False
twonumberstf=False
threeletterstf=False
valid=False
speed=0
ticketprice=0
ticket=False
distance=10
#Calculations to work out the speed
time.sleep(1)
distance=10
times=sensor2-sensor1
ans=1/times
speed=distance*ans

#If more than 7 letters and numbers
if len(np)>7 or len(np)<7:
    valid=False
    print("Invalid Nuber Plate")
#If less than 7 letters and numbers outputs number plate and speed
#If their is upper case letters and digits in correct order
elif twoletters.isupper() and twoletters.isalpha and twonumbers.isdigit() 
and threeletters.isupper() and threeletters.isalpha():
    valid=True
    twoletterstf=True
    twonumberstf=True
    threeletterstf=True

#If isn't upper case or their isn't 2 numbers or if their isnt't three letters, then outputs the number plate with speed
elif twoletterstf==False or twonumberstf==False or threeletterstf==False:
    print("Invalid Number Plate")
    valid=False
elif speed > 31:
    ticket=True
    ticketprice=100+speed
elif speed < 31:
    ticket=False
    ticketprice=0
else:
    exit

f=open("Output.txt", "a")
f.write("Number Plate:" + str(np) + "\n")
f.write("Valid:" + str(valid) + "\n")
f.write("Speed:" + str(speed) + "M/S" + "\n")
f.write("Ticket:" + str(ticket) + "\n")
f.write("Ticket Price: £" + str(ticketprice) + "\n")
f.write("\n")
f.close()

이것은 문제이며, elifs는 실제로 작동하지 않으므로 마치 존재하지 않는 것처럼 작동합니다. 텍스트 문서의 코드를 작성할 때 실제로 속도가 빠르면 항상 거짓으로 나타나고 결코 사실이 아닙니다. 그래서 누군가 도울 수 있다면 진정한 도움이 될 것입니다

elif speed > 31:
    ticket=True
    ticketprice=100+speed
elif speed < 31:
    ticket=False
    ticketprice=0

  • 답변 # 1

    #Imports
    import time
    import random
    #If more than 7 letters and numbers
    def CheckPlate(np):
        IsPlateValid = False
        if len(np) != 7:
            print("Invalid Plate Number!")
        else:
            IsPlateValid = True
        return IsPlateValid
    #If less than 7 letters and numbers outputs number plate and speed
    def CheckPlateContent(twoletters, twonumbers, threeletters):
        twoletterstf=False
        twonumberstf=False
        threeletterstf=False
        valid = False
        for letter in twoletters: #I have to use (for x in Xs) because of array input but your format should work fine here  if input is user input
            if letter.isupper() and letter.isalpha():
                twoletterstf = True
        for number in twonumbers:
            if number.isdigit():
                twonumberstf = True
        for letter in threeletters:
            if letter.isupper() and letter.isalpha():
                threeletterstf = True
        if (twoletterstf == True and twonumberstf == True and threeletterstf == True):
            valid= True
        else:
            print("Invalid Plate Number!")
        return valid
    def SpeedCheck(speed):
        ticket = False
        ticketprice = 0
        if speed >= 31:
            ticket=True
            ticketprice=100+speed
        return ticket, ticketprice
    def main():
        #Gets the number plate
        np=['A','C','4','2','F','G','H'] #input is an array because I id this on Atom and there is no input console.
        #Sets the parts of the license plate
        twoletters=np[0:2]
        twonumbers=np[2:4]
        threeletters=np[4:7]
        #Sensors
        sensor1=0
        sensor2=random.uniform(0.25, 0.4)
        sensor2=round(sensor2, 1)
        #Variables
        speed=0
        ticketprice=0
        ticket=False
        distance=10
        #Calculations to work out the speed
        time.sleep(1)
        distance=10
        times=sensor2-sensor1
        ans=1/times
        speed=distance*ans
        bool = CheckPlate(np)
        valid = CheckPlateContent(twoletters, twonumbers, threeletters)
        ticket, ticketprice = SpeedCheck(speed)
        print ("Number Plate:" + str(np) + "\n")
        print ("Valid:" + str(valid) + "\n")
        print ("Speed:" + str(speed) + "M/S" + "\n")
        print ("Ticket:" + str(ticket) + "\n")
        print ("Ticket Price: £" + str(ticketprice) + "\n")
    
    if __name__ == "__main__":
        main()
    
    

  • 이전 ftp - 하나의 URL에서 SPA와 함께 정적 웹 사이트를 제공하는 방법
  • 다음 android - 활동 인식은 오레오에서 서비스를 계속합니다