Thanks for the reply. So to append a word is it suppose to look kind of like:
word=raw_input("Name #1: ") word.append(words) I keep getting error message: Traceback (most recent call last): File "/Users/JT/Desktop/pythonfinal", line 23, in <module> CollectNames() File "/Users/JT/Desktop/pythonfinal", line 7, in CollectNames word.append(words) AttributeError: 'str' object has no attribute 'append' On May 18, 2011, at 5:39 AM, Corey Richardson wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On 05/18/2011 08:26 AM, Johnson Tran wrote: >> Hi Again All, >> >> I had a couple questions about my program: >> >> def CollectNames(): >> >> answer_set=set([]) >> sorted_list = sorted(answer_set) >> word=raw_input("Name #1: ") >> >> word=raw_input("Name #2: ") >> >> word=raw_input("Name #3: ") >> >> word=raw_input("Name #4: ") >> >> word=raw_input("Name #5: ") >> >> print "Your answer's sorted: ", ','.join(sorted_list) >> >> CollectNames() >> >> >> 1.) how do i add each answer given to the list so it is printed at the end? > > Well, you can't have ALL the answers printed at the end, but one way is > to use a list and .append(word) each time. > >> 2.) also im trying to modify the program so if the user puts in the same >> name, it will give an make them try again until they have 5 completely >> different names. > > Now, you might see a pattern in your prompt. Each time you ask for > input, you increment the name number. Perhaps this is the prime place > for a loop? If you add in a loop, it will also be fairly easy to add in > another loop to make sure they enter a name not in the list. So, your > pseudo-code might look something like this: > > for i in range(6): > make prompt string; > get name; > while name in names_gotten: > get name; > add name to names_gotten; > print names_gotten; > > (P.S., PEP 8 says functions should be lowercase_with_underscore, > not CamelCase) > - -- > Corey Richardson > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v2.0.17 (GNU/Linux) > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ > > iQEcBAEBAgAGBQJN074TAAoJEAFAbo/KNFvpdHwIAK1Ji+4Z3Fac0wtH2EgBDwp2 > K8t10KpbtRYfWOCjiYfBAzZFWLrQ9I+lrmdth7Asf0ANg72U4gPHkp82ZbO8mhyz > 02eDBPXboAmLcntxsxcmMkNlG1xPVeXjcriGwX/VcN2AguGKvrKkKbkkT+Ar+bWZ > ZpjH0ycNsAUTNeQLQEHJQJtPMktJ13XvlrjHN0YVoLpk812rAn+nuTZq+p0J5fzc > hCgyxUiRcHYllXZv/1AegOWbfon3BMur9fpV2UMo8JcsRTHto3Lb5c3jHqApNjfc > M48rpigGXjOzowj0WbsMmSHrskBglcSAy+xo/Ti0vnBXDMU3secWFWkaxDtdidk= > =oCrn > -----END PGP SIGNATURE----- > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor