我试图完成这段代码,它会要求用户输入他们的名字和他们最喜欢的食物是什么,它会不断地询问用户是否要添加更多的数据。当用户输入'N'时,我需要完整的表格,将所有的输入一起打印出来,有人知道如何做到这一点,而不是一个接一个?你知道吗
def get_string_inputs (p) :
''' requests the string data and returns it'''
strData=input("Please enter {0} : ".format(p))
return strData
def add_data_rows () :
''' adds data to the row array'''
meal_details = [ ]
#the helper function is used here
name = get_string_inputs("your name ").capitalize()
meal_details.append(name)
favourite_meal = get_string_inputs("your favourite food").capitalize()
meal_details.append(favourite_meal)
return meal_details
def main() :
'''runs all functions'''
favMeal = []
header=['Name','Favourite Meal']
favMeal.append(header)
meal_details = add_data_rows()
favMeal.append(meal_details)
for a,b in favMeal:
print('{0:16}{1:<16}'.format(a,b))
while True:
valid_option = ['Y','N']
question = input("Would you like to add more data? (Y/N): ").upper()
if question in valid_option:
if question == 'Y' :
main()
if question == 'N' :
??????
break
else:
print("That is not a valid choice, Please enter Y or N")
main()
你有点不对劲,我在我改的台词上做了笔记。 我希望这有帮助。你知道吗
相关问题 更多 >
编程相关推荐