jeudi 19 avril 2018

Python 3: How to have the "else" statement apply only if none of the "if" statements are true?

Sorry, beginner here. Trying to make this program that scans for a certain letter combination, and if it does not find any, it returns the "else" statement. However, I can't figure out how to have the "else" statement apply ONLY if ALL of the "if" statements return False. Here's my code:

class color:
BOLD = '\033[1m'
END = '\033[0m'
GREEN = '\033[92m'

print("Welcome to the Sequence Scanner")
print(" ") ## just putting a space between the welcome message and the input box
seq = input("Provide your nucleotide sequence here: ")

def scan():
    if 'aataaa' in scan():
        print('The trouble sequence, Canonical Poly-A Signal, is present')
    if 'aatgga' in scan():
        print('The trouble sequence, Pea Poly-A Signal, is present')
    ### the same format for the previous if statements is repeated for different sequences 
    else: 
        print(color.GREEN + 'No trouble sequences are present' + color.END)
scan(seq)

Right now, it prints the "else" statement any time the last "if" statement is false. So I'm assuming I need to make it so it's not just applying to the last "if" statement, but I've tried different indentations and it just doesn't work for me.

I know this is probably a really stupid question, so I'm sorry in advance. Also, if there are any other things I should do/know about to make this code more efficient, it would be awesome if you could point me towards resources for that! Thanks for any help, I really appreciate it.

Other questions if you're really bored and want to help me out at all: is there any way to make the function print the input sequence with the "trouble sequences" highlighted (like in red or something)? That would be awesome, but it seems like it might be too hard for me to pull off with my current level of coding experience.

Aucun commentaire:

Enregistrer un commentaire