【发布时间】:2020-02-05 03:57:58
【问题描述】:
这是一个 Python 类的入口。我必须至少使用一个主要功能和两个其他功能。当我运行时,它只是一遍又一遍地打印“你已经预订了你的旅行吗?请输入是或否”。相反,我试图让它首先询问这个人是否已经预订了他们的旅行。如果是,它会继续询问他们的性别。然后是他们目的地的季节。然后程序会相应地生成一个装箱单。
# Welcome the user
def main():
print('Welcome the Personalized Packing List Generator. '
'In order to generate your list, you will have to provide some information about yourself and your trip.')
# function that checks whether the users' trip has been booked or not.
def tripBooked():
booked = input("Have you booked your trip already? Please enter yes or no.")
if booked == 'no' or booked == 'No':
print('Please return once your trip has been confirmed')
else:
print('Lets get to know you a bit better')
# Lists 1-4 are for everyone
list1 = ("Documents: Tickets, passport, itinerary.")
list2 = ("Clothing: Tops, pants, shoes, socks, undergarments.")
list3 = ("Electronics: Chargers, headphones.")
list4 = ('Hygiene: Toothbrush, toothpaste, floss, deodorant, hairbrush.')
# List 5 is for women
list5 = ("Makeup and cosmetics, jewelry, handbag, hair ties, straightener or curling rod.")
# List 6 is for men
list6 = ("Ties, cufflinks, razor, shaving gel, after shave.")
# List 7 for winter
list7 = ("Coat, hat, scarf, boots, warm socks, thermals.")
# List 8 is for fall/spring
list8 = ("Outerwear: Light jacket, cardigan, raincoat.")
# List 9 for summer
list9 = ('Flip flops, sunscreen, hat, bathing suit, sunglasses.')
finalList = list1 + list2 + list3 + list4
# List generator function
def genderListGenerator():
gender = input('What is your identified gender? Please enter male or female.')
print('Here is what we recommend as basic things to take with you:', finalList)
if "male" == genderListGenerator() or genderListGenerator() == 'Male':
print('finalList += list6')
elif genderListGenerator() == 'female' or genderListGenerator() == 'Female':
print('finalList += list5')
def seasonListGenerator():
season = input('What season is it where you are going? Please enter winter, fall, spring, or summer.')
if seasonListGenerator == "winter" or seasonListGenerator == 'Winter':
print('finalList += list7')
if "fall" or seasonListGenerator == 'Fall' or "spring" == seasonListGenerator or seasonListGenerator == 'Spring':
print('finalList += list8')
if seasonListGenerator == "summer" or seasonListGenerator == 'Summer':
print('finalList += list9')
【问题讨论】:
-
您熟悉调试工具吗?使用逐步执行将大大提高您自己发现执行流程问题的能力。大多数情况下,它从一开始就节省了大量的 stackoverflow 问题。
-
genderListGenerator()函数不返回值(因此它默认返回None。)所以当你进行像if "male" == genderListGenerator()这样的比较时,这种比较永远不会成立。跨度> -
这证明了以下几点:1- 使用调试器,2- 在编写任何代码之前考虑程序流程、变量、交换,3- 阅读有关函数调用和返回值的文档
-
LoneWanderer- 不幸的是,我们没有在课堂上学习调试,我也没有足够的时间自学。
标签: python function functional-programming main