gpt4 book ai didi

python - 入场费根据年龄而定

转载 作者:太空宇宙 更新时间:2023-11-03 15:33:37 25 4
gpt4 key购买 nike

我正在尝试设计一个程序,您可以根据年龄计算门票价格。价格为:14 岁及以下(5.00 美元)、15 至 64 岁(9.00 美元)和 65 岁及以上(7.50 美元)。顾客还可能有一张优惠券,可以从他们的价格中扣除一美元。到目前为止我已经想出了:

print ("Hello, welcome to Hopper's Computer Museum! To determine your enterance fee, please enter the following:")

print ('Your Date of Birth (mm dd yyyy)')
Date_of_Birth = input("--->")

print ('Todays Date: (mm dd yyyy)')
Todays_Date = input("--->")

age = (tYear-bYear)
if (bMonth > tMonth):
age == age-1
if (bMonth == tMonth and
bDay > tDay):
age == age-1

price = -1
while price == -1:
try:
age = int(input('age:'))
excpet ValueError:
print("Not a number, try again.")
continue
if age <= 14:
price==5.00
elif age > 15 and age < 64:
price==9.00
else age > 65:
price==7.50

print ('Do you have a coupon (y/n)?')
Discount = input("--->")
if Discount == "y" or Discount == "Y":
price = price-1
elif Discount == "n" or Discount == "N":
price = price

print ('Your admission fee is '+str(price)')

我感到困惑的一件事是如何让 Python 获取用户输入的日期并将其放入我设置的年龄计算中。

最佳答案

您可以指定要采用的日期格式,然后将其拆分为...

import datetime
date_entry = input('Enter a date in YYYY-MM-DD format')
year, month, day = map(int, date_entry.split('-'))
date1 = datetime.date(year, month, day)

或者您可以引用以下链接了解更多信息...

getting-input-date-from-the-user-in-python-using-datetime-datetime

how-to-have-user-input-date-and-subtract-from-it

how-do-i-take-input-in-the-date-time-format

关于python - 入场费根据年龄而定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42711246/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com