I am trying to create temporary lists to store individual weekly data for each store(I ask the user what the name of your store is and then ask about their daily sales for the week, which I then want to append into a separate list, but I don't know how to do it for multiple user inputs, which all have different sets of daily data for the week), I have created a permanent list to store all store's data in one list. I am trying to create temporary lists for each store's data so that I can make a 2D list as a requirement in my project. I hope you understand.
All_Store_Daily_income = []
days_of_the_week = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
is_last_weekday = None
def get_daily_store_data():
Day_Counter = 0
while Day_Counter < 7:
try:
Daily_sales = float(input(f"What is the income for {days_of_the_week[Day_Counter]}? "))
All_Store_Daily_income.append(Daily_sales)
print(All_Store_Daily_income)
Day_Counter = Day_Counter 1
global is_last_weekday
is_last_weekday = Day_Counter == 7
except ValueError:
print("Please enter a integer or float, no letters allowed!")
def store_adder_programme():
Store_name_list = []
number_of_stores = 1
Adding_stores = 'y'
while Adding_stores == 'y':
store_name = input("What is the name of your registered store? ")
Store_name_list.append(store_name)
get_daily_store_data()
print(Store_name_list)
if (is_last_weekday == True) and (Adding_stores == 'y'):
print('Would you like to add a new store?')
Adding_stores = input("If YES(y), If NO(n): ")
print(All_Store_Daily_income)
number_of_stores = number_of_stores 1
store_adder_programme()
CodePudding user response:
This is one way to do it. I put some inline comments to help explain what I did.
All_Store_Daily_income = [] # this becomes 2D list
days_of_the_week = ["Monday", "Tuesday", "Wednesday", "Thursday",
"Friday", "Saturday", "Sunday"]
is_last_weekday = None
def get_daily_store_data():
seq = [] # create a list
Day_Counter = 0
while Day_Counter < 7:
try:
Daily_sales = float(input(f"What is the income for {days_of_the_week[Day_Counter]}? "))
seq.append(Daily_sales) # fill list with store data
Day_Counter = Day_Counter 1
global is_last_weekday
is_last_weekday = Day_Counter == 7
except ValueError:
print("Please enter a integer or float, no letters allowed!")
return seq # return list
def store_adder_programme():
Store_name_list = []
number_of_stores = 1
Adding_stores = 'y'
while Adding_stores == 'y':
store_name = input("What is the name of your registered store? ")
Store_name_list.append(store_name)
store_data = get_daily_store_data() # get list from function return value
All_Store_Daily_income.append(store_data) # append returned list to All_Store_Daily_income
print(Store_name_list)
if is_last_weekday and Adding_stores == 'y':
print('Would you like to add a new store?')
Adding_stores = input("If YES(y), If NO(n): ")
print(All_Store_Daily_income) # prints the 2D list
number_of_stores = number_of_stores 1
store_adder_programme()