This is a very basic question, but I can't seem to extend an array with a new item that is added within a function. I haven't gotten push to work either, so I think my array is just not being addressed by the other functions.
The array is declared as a global because otherwise function(s) do not appear to be able to see it. There is probably a much better way, but this is working in a few ways.
this is one set of things I've tried:
# addTo.insert(0, theItem)
# weeklytasks.append(theItem)
# print(addTo)
# def askForItem(theItem):
# addTo.push(theItem)
# print(addTo)
#
but no luck.
def initializer():
print("hello!")
print("do you want to view the current list, or add a new item?")
setting up some arrays
global weeklyTasks = ['no items'];
global monthlyTasks = ['no items']
global quarterlyTasks = ['no items'];
trying to extend
quarterlyTasks.extend('the item')
print(quarterlyTasks);
Neither of these work
#monthlyTasks.push(0,"task1")
#monthlyTasks.append("item")
set a var for user's input
global theItem
addTo = ""
theItem = ""
import string
print('addTo in globals, ' 'addTo' in globals())
takes an item and checks its timeframe
def evaluateInput(timeframe):
global addTo;
global theItem;
if timeframe == "Weekly":
addTo = "weeklyTasks";
printDestination();
weeklyTasks.extend(theItem); # why does [].extend not work here?
if timeframe == "Monthly":
addTo = "monthlyTasks"
monthlyTasks.insert(0,theItem)
printDestination()
if timeframe == "Quarterly":
addTo = "quarterlyTasks"
quarterlyTasks.insert(0,theItem)
printDestination()
follow up with a request for the timeframe
def getTimeframe(text):
if "add" in text:
timeframe = input("Where does this entry go? \n Weekly, Monthly or Quarterly?: ")
evaluateInput(timeframe) # sends the timeframe to evaluateInput
# next, ask for the item
theItem = input('what is the item?')
print a confirmation of what is being added where
def printDestination():
print("The item (" + theItem+") will be added to " + addTo)
# prints where something is going
print("the "+addTo+" list now contains:") # good, this worked
print(weeklyTasks) #good, this worked (but the method to push doesn't work)