入学价格根据年龄和优惠券

时间:2017-02-21 08:16:04

标签: python price

我试图在用户提示今天的日期及其出生日期时编写代码,以确定他们的年龄。年龄将决定他们的门票价格。如果他们14岁以下,价格将是5美元。如果他们是15到64,价格将是9美元,如果他们是65岁以上,价格将是7.50。它会询问客户是否有优惠券,可以从他们的价格中扣除1美元。到目前为止我所拥有的:

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

if age < 14:
    price==5.00
elif age > 15 and age < 64:
    price==9.00
elif 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 $4.00 enjoy your visit!')

我知道我需要定义我的变量,例如tYear,bYear,bDay等,但我不确定应该将它们分配给它们。

1 个答案:

答案 0 :(得分:1)

您可以使用map为tYear,bYear等分配值。您可以执行以下操作而不是Date_of_birth = input('---&gt;')

    bDay,bMonth,bYear = map(int,raw_input('--->').split())

如果输入格式为'dd mm yyyy',这将根据要求分配bDay,bMonth和bYear。同样地,今天的日期你可以写:

    tDay,tMonth,tYear = map(int,raw_input('--->').split())

备用选项是使用日期时间计算年龄。请遵循此 - Age from birthdate in python