1

why my code is always printing empty list_of_lists ?? There is nothing wrong with the class and all functions is well implemented

I think that the problem is the way i am using the loop but i can not discover ... What i should do to fix this? as you see i am still beginner

Note: i did not add the Class and the functions here not to be long code.

print("Consider this format=> normal: 20Mar2009(fri), 21Mar2009(sat), 22Mar2009(sun)")

info = input("")

client_type = get_client_type(info)      #function that return client type 

given_dates = get_given_dates(info)      #function that return a list with several dates

day_type = get_day_type(info)  #function that process the given date and return "workday" or "holiday"

days_num = len(given_dates)

list_of_lists = []

for date in given_dates:
    
    if day_type == "holiday" and client_type == "normal":                        
        list1=[]    
        list1.append(Hotel.normal_holiday(hotel1)) #Refere to the class Hotel created before
        list1.append(Hotel.normal_holiday(hotel2))        
        list1.append(Hotel.normal_holiday(hotel3))
        list1 = list(map(int, list1))               
        list_of_lists.append(list1)
        print(list_of_lists)
    
    elif day_type == "workday" and client_type == "normal":
        pass  
Frodon
  • 3,684
  • 1
  • 16
  • 33
  • 1
    What would an example output of `Hotel.normal_holiday()` look like? In any case using `list(map(int, list1))` to convert from integer to string is not the best way as it can cause problems, check out this thread: https://stackoverflow.com/a/10145364/18189622. A better way to do this would be `list1 = [int(i) for i in list1]` or directly using `list_of_lists.append([int(i) for i in list1])`. – ewz93 May 06 '22 at 22:29
  • The output is going to be number – Malis Lenson May 06 '22 at 22:30
  • In this case it should work, I tried your code with three random integer numbers and it prints a nested list for me, like `[[1,2,3]]`. Are you sure your code reaches this part of the code and this is where an empty list is printed? And your code snippet is missing a closing bracket here -> `.normal_holiday(hotel1) #Refere to the class...`, is that different in your original code? – ewz93 May 06 '22 at 22:36
  • If `day_type != "holiday"` or `client_type != "normal"` then your condition won't be satisfied and thus `list_of_lists` won't be updated. This variables are not being modified in the `for` loop so I would check that their values first to ensure that your code is running inside the first part of the `if` statement. – mtzd May 06 '22 at 22:38

0 Answers0