python adds specific inputs to a variable or function

You need to use a for loop, and add brackets in order for it to be a list comprehension:

def main():
    code = input("Please enter all codes of your products in format 'AB123':")
    print("Your codes are:", code)
    codes = [c for c in code.split() if len(c) == 5 and c[:2] == 'AB' and c[-2:] == '00']  
    if codes:
        print("Ok, here are your prioritized codes", codes)
        print("There are no codes with 'AB' letters and '00' digits at the end!")



Please enter all codes of your products in format 'AB123':AB100 UI812 GS901 AB300


Your codes are: AB100 UI812 GS901 AB300
Ok, here are your prioritized codes ['AB100', 'AB300']

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top