I am writing a program that should check if:
- a user input string contains a specific word
- OR contains 4 designated characters and is divisible by 3.
I can get the specific string check and the divisibility check to work but I can't seem to get the letter check to work.
validationcheck = False
while not validationcheck:
InputSequence = input("Input: ")
if (InputSequence == 'EXAMPLE' or len(InputSequence) % 3 == 0 and 'C', 'A', 'G', 'T', 't', 'g', 'a','c' in InputSequence):
validationcheck = True
else:
print("Invalid input")
InputSequence = input("Input: ")
My desired output would be that if the user types EXAMPLE
, or they type a sequence of letters containing C
, A
, G
, T
that is divisible by 3, there would be no invalid input. Otherwise the program would print an invalid input message and prompt the user to re enter
Update - I ended up solving it but thanks for the reponses. I ended up using the following if it is helpful for anyone
validationcheck = False
while not validationcheck:
InputSequence = input("Input: ")
stringToCheck = InputSequence
found = re.search("[CAGT]", stringToCheck)
if len(InputSequence) % 3 == 0 and found:
validationcheck = True