Skip to main content
 首页 » 编程设计

python如何使用通配符查找数字

2024年10月24日9powertoolsteam

<分区>

在我的工作中,我收到来自制造商的纸箱。纸箱有序列号,某些纸箱(前 5 个,以 20、50、90 结尾的那些和最后 5 个)必须打开和检查。从下面的代码可以看出,我想我已经确定了第一个和最后五个纸箱的问题。我对以 20、50、90 结尾的那些感到难过。 first_carton 和 last_carton 编号取决于当前的纸箱批处理。

    """ 
This script helps arrange cartons for inspection 
How the system works: 
* Lay out the first 5 cartons in the list 
* Lay out the last 5 cartons in the list 
* Lay out cartons ending with 20, 50, 90 
""" 
#Prompt the user to enter the first carton number 
first_carton = int(input("First Carton: ")) 
#The last carton number 
last_carton = int(input("Last Carton: ")) 
 
#Make the first carton number and last carton number (+1) into a range 
# and make all the numbers inthe range into a list 
carton_list = list(range(first_carton, last_carton+1)) 
 
#Get the first and last 5 carton numbers by slicing the carton list 
firstFive = carton_list[0:5] 
lastFive = carton_list[-5:] 
 
# Function to print out numbers ending in 20, 50, and 90 
def print_20_50_90_cartons(): 
    for i in carton_list: 
        if i #ENDS WITH 20,50,90#: 
            print(i)