Python - Elif不工作,只是跳过了

时间:2018-05-25 12:18:20

标签: python if-statement

这是我的ANPR相机代码,它扫描许可证,版块并检查它们是否超速,并将所有信息写入名为output.txt的文本文档。所有这些都不是一个部分,见底部。它也没有出现错误代码

#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()

这就是问题所在,精灵实际上并没有工作,所以就好像他们不在那里一样。当它在文本文档中编写代码时,它总是出现错误,如果它们实际上正在超速则永远不会如此。如果有人能帮助它将是一个真正的帮助

elif speed > 31:
    ticket=True
    ticketprice=100+speed

elif speed < 31:
    ticket=False
    ticketprice=0

1 个答案:

答案 0 :(得分:0)

.modalDialog iframe  { width: 100%;
height: 100%;}

.modalDialog {
    position: fixed;
    font-family: Arial, Helvetica, sans-serif;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(0,0,0,0.8);
    z-index: 99999;
    opacity:0;
    -webkit-transition: opacity 400ms ease-in;
    -moz-transition: opacity 400ms ease-in;
    pointer-events: none;
    -webkit-overflow-scrolling: auto;       

}

.modalDialog:target {
    opacity:1;
    pointer-events: auto;
-webkit-overflow-scrolling: auto; 
}

.modalDialog > div {
    width: 80%;
    height: 600px;
    position: relative;
    margin: 10% auto;
    padding: 5px 20px 13px 20px;
    border-radius: 10px;
    background: #fff;  
-webkit-overflow-scrolling: auto;
    overflow: auto;
    overscroll-behavior: contain;         

}
::-webkit-scrollbar {
            -webkit-appearance: none;
            width: 20px;
}
::-webkit-scrollbar-thumb {
            border-radius: 4px;
            background-color: rgba(0,0,0,.5);
            box-shadow: 0 0 1px rgba(255,255,255,.5);
}

.close {
    background: #606061;
    color: #FFFFFF;
    line-height: 25px;
    position: absolute;
    right: 5px;
    text-align: center;
    top: 5px;
    width: 24px;
    text-decoration: none;
    font-weight: bold;
    -webkit-border-radius: 12px;
    -moz-border-radius: 12px;
    border-radius: 12px;
    -moz-box-shadow: 1px 1px 3px #000;
    -webkit-box-shadow: 1px 1px 3px #000;
    box-shadow: 1px 1px 3px #000;
}

.close:hover { background: #00d9ff; }