+ 1

Need help iterating through words from each index in list

So I've been trying to create an A.I. that remembers what you say by storing it in a list, but need help iterating through each word within the list. Any way of doing so? I'm planning on teaching it what each word means in order to give you a natural response, not just some custom strings based on "ifs" lol. Anyway here is the code, please run it in qPython3 app for it to work . Thanks👽👁️ https://code.sololearn.com/cFgYxhEP6FYr/?ref=app

2nd Jul 2017, 10:54 PM
AFX LAB
AFX LAB - avatar
1 Réponse
+ 2
Actually you're just defining a 'speak()' function wich input ten word to user, speaking last stored and displaying list of stored words... and you call it in another loop, so you ask user for 200 words (20*10 times): for _ in range(20): speak() Did you rather trying to speak all stored words after storinf them once time? (but ranges are not corresponding) If so, or for use it later, you need to export the list outside of your function, either by returning the 'key' list from your function and storing it elsewhere, or by using a global variable: mylist = [] # global scope def myfunc(): temp = 42 # function scope global mylist # allow write access (access without declaring 'global' will be read only) # but I would do rather the return way: mylist = [] # global scope / shared variable def myfunc(): temp = [] # fill the temporary list return temp mylist = mylist + myfunc() # append the returned list to the global list
3rd Jul 2017, 12:22 AM
visph
visph - avatar