samedi 1 octobre 2016

Program with querying python list with multiple values using for loop and if in statements

I know the title is a little messy and if someone wants to fix it, they are more than welcome to.

Anyways, I'm having trouble querying a python list with multiple values, I have looked on other Stackoverflow questions and none of seem to match what I'm looking for.

So, this is the code I have so far, its supposed to use a for loop statement, so that it goes through each character and then uses and if in statements to check whether a character in the user input matches anything in the list.

In my example, it only uses symbols, but hopefully that shouldn't be much of a problem

Anyways here is the code

string = input("What symbol character would you like to check")
symbols=[' ', '!', '#', '$', '%', '&', '"', '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_', '`', '{', '|', '}', '~',"'"]
def symbol():
    for x in symbols:
        if x =='!':
            return True
        elif x !='!':
            return False

if symbol():
    print('ok')
if not symbol():
    print('What Happened?')

Aucun commentaire:

Enregistrer un commentaire