函数循环和数组

时间:2017-05-15 00:04:38

标签: arrays function loops

    def write_schedule(week_timetable, open_time_table):
        print "Please enter Weeks sechdule: "
        week = [mon,tues,wed,thur,fri,sat,sun]
        for i in week:
             print "Please enter day 1: "
            # here i would like to input a time into each variable within       the week array i have created
           # later on in my script i would like to insert each time into my global array 
          # week_timetable = ["Mon: %s ", "Tues: %s ", "Wed: %s ", "Thurs: %s ", "Fri: %s", "Sat: %s", "Sun %s"]

我正在尝试使用循环每次输入到数组列表中。我想从用户那里输入原始输入,然后将其保存到每个数组中。函数完成循环后,我希望将每个变量保存到我的全局数组中。我有点坚持这个,如果我没有意义,那么请参考我上面代码中的评论。

1 个答案:

答案 0 :(得分:0)

我假设所有日期都是获取数据的对象。如果是这样,我调用for day in week使其更清晰,然后将用户输入添加到日期对象中作为建模。

如果周只是一个数组数组,那么你可以在同一个循环中使用day.append(input)。当你完成循环时,星期数组将包含所有修改过的对象/数组,供你随意使用。