As the title says, how do I check whether an input string has alphabets in another string in Python?
The string specifies that only alphabets A to G ('ABCDEFG') can be used in the input string. However, my attempt did not get the results I want. Instead, input strings with alphabets in order such as 'ABC' and 'ABCD' work, while those not in order such as 'BADD' and 'EFEG' do not.
Please refer to my attempt below.
ID = 'ABCDEFG'
addcode=input('Enter new product code: ')
Code = []
if addcode in ID:
Code.append(addcode)
print(Code)
else:
print("Product code is invalid")
Ideally, as long as the input string contain letters from A to G, it should be appended to 'Code' regardless of the order. How do I modify my code so that I can get the results I want? Thank you.
Aucun commentaire:
Enregistrer un commentaire