mardi 20 février 2018

Using append with a Variable in an if Statement Python

I am trying to create a way to add input values to my lists through a user interface that asks you what the category and what word you would like to add it to. It all works just fine, and as you can see I was trying it out with my test category(the reason for the seemingly unnecessary print statements) except for one thing; the append statement. I want to find a way to put the inputted category in the spot before the append so that the phrase that i want to add will be added to that category. I am not sure what to put so I tried a number of things: list, (list), userCategory (which is in there now), and (userCategory). I think it is probably a syntax error but it just tells me that those names can't be appended to. This is the error message.

AttributeError: 'str' object has no attribute 'append

This is my code

testcategory = ['chicken',]
greetingInput = ['hi','HI','Hi','Hello','wazzup','hello','sup','Sup','howdy','Howdy','hey','Hey','What\'s hanging my dude?',]
greetingOutput = ['Hello, how are you?','How\'s it going?','Wazzup','What\'s hanging my dude?',]
greetingResponseP = ['good','great','ok','fine','okay','amazing','splendid','Good','Great','Ok','Fine','Okay','OK','Amazing','Splendid','allright','Allright',]
greetingResponseB = ['bad','sucky','lame','not good','horrible','cruddy','bloody horrible','terrible','Bad','Sucky','Lame','Not good','Horrible','Cruddy','Bloody horrible','Not Good','Bloody Horrible','Terrible']
statusInputandResponseP = ['Good, how are you?','I\'m great, how are you?','i\'m good, how are you?','Good how are you?','I\'m great how are you?','i\'m good how are you?','Im great, how are you?','im good, how are you','Good, how are you','I\'m great, how are you','i\'m good, how are you','Im great, how are you','im good, how are you','Good, hbu?','I\'m great, hbu?','i\'m good, hbu?','Good hbu?','I\'m great hbu?','i\'m good hbu?','Im great, hbu?','im good, hbu','Good, hbu','I\'m great, hbu','i\'m good, hbu','Im great, hbu','im good, hbu','Good how are you?','I\'m great how are you?','i\'m good how are you?','Im great how are you?','im good how are you','Good how are you','I\'m great how are you','i\'m good how are you','Im great how are you','im good how are you','Good hbu?','I\'m great hbu?','i\'m good hbu?','Im great hbu?','im good hbu','Good hbu','I\'m great hbu','i\'m good hbu','Im great hbu','im good hbu',]
statusInput = ['how are you','How are you','how about you','How about you','hbu','HBU','how are you?','How are you?','how about you?','How about you?','hbu?','HBU?','How\'s it going?','how\'s it going?','how\'s it going','How\'s it going','Hows it going?','Hows it going','How\'s it goin\'?','how\'s it goin\'?','how\'s it goin\'','How\'s it goin\'','Hows it goin\'?','Hows it goin\'','How\'s it goin?','how\'s it goin?','how\'s it goin','How\'s it goin','Hows it goin?','Hows it goin',]
userCategory = input("Enter Category: ")
def addInput(list):
        print (testcategory)
        userWord = input("Input the word: ")
        if userCategory == str(list):
                userCategory.append(userWord)
                print (testcategory)

addInput(userCategory)

Thank you for your help.

Aucun commentaire:

Enregistrer un commentaire