为每组用户输入创建临时列表
Creating Temporary lists for Each set of user inputs
我正在尝试创建临时列表来存储每个商店的个人每周数据(我询问用户您商店的名称是什么,然后询问他们本周的每日销售额,然后我想将其附加到一个单独的列表,但我不知道如何针对多个用户输入执行此操作,这些输入都有不同的一周每日数据集),我创建了一个永久列表以将所有商店的数据存储在一个列表中。我正在尝试为每个商店的数据创建临时列表,以便我可以在我的项目中制作一个 2D 列表作为要求。希望大家理解。
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()
这是一种方法。我放了一些内联评论来帮助解释我所做的事情。
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()
我正在尝试创建临时列表来存储每个商店的个人每周数据(我询问用户您商店的名称是什么,然后询问他们本周的每日销售额,然后我想将其附加到一个单独的列表,但我不知道如何针对多个用户输入执行此操作,这些输入都有不同的一周每日数据集),我创建了一个永久列表以将所有商店的数据存储在一个列表中。我正在尝试为每个商店的数据创建临时列表,以便我可以在我的项目中制作一个 2D 列表作为要求。希望大家理解。
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()
这是一种方法。我放了一些内联评论来帮助解释我所做的事情。
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()