首页 > 解决方案 > 它没有打印出我想打印的东西

问题描述

我做了我能做的,但它不会打印我想要的东西,但它只是出来了“电子票务自动化系统成人人数:3 孩子人数:3 老人人数:3 什么样的会员资格 1 为公司或 2 为家庭: 1 有信息输入错误请重新输入以上信息。

进程以退出代码 0 结束”

print("E Ticketing Automation System")

#a for adult b for kids and c for elderly
a = int(input("Numbers of adult: "))
b = int(input("Numbers of kids: "))
c = int(input("Numbers of elderly: "))
membership = input("what kind of membership 1 for corporate  or 2 for 
family: ")

totalprice = (a*10.00) + (b*7.50) + (c*5.50)
kiddo=b*7.50


corporate = totalprice-(totalprice/100)*20
ccorporate=(totalprice/100)*20
family = totalprice-(b*7.50)


if membership == 1:
   print("The original price before discount is $,",totalprice,"after 20 
   percent discount",ccorporate, "the total price will be $",corporate, )
elif membership == 2:
   print("The original price is $",totalprice,"but after deduction of the 
   kids price $",kiddo,"the total price will be $",family,)
else:
   print("there is information inputted incorrectly pls re-enter the info 
   above.")

标签: python

解决方案


我猜您忘记将变量的输入membership视为int.

这是更新的源代码,

print("E Ticketing Automation System")

#a for adult b for kids and c for elderly
a = int(input("Numbers of adult: "))
b = int(input("Numbers of kids: "))
c = int(input("Numbers of elderly: "))
membership = int(input("what kind of membership 1 for corporate  or 2 for family: "))

totalprice = (a*10.00) + (b*7.50) + (c*5.50)
kiddo=b*7.50


corporate = totalprice-(totalprice/100)*20
ccorporate=(totalprice/100)*20
family = totalprice-(b*7.50)


if membership == 1:
   print("The original price before discount is $,",totalprice,"after 20 percent discount",ccorporate, "the total price will be $",corporate, )
elif membership == 2:
   print("The original price is $",totalprice,"but after deduction of the kids price $",kiddo,"the total price will be $",family,)
else:
   print("there is information inputted incorrectly pls re-enter the info above.")

预期输出:

E Ticketing Automation System
Numbers of adult: 3
Numbers of kids: 3
Numbers of elderly: 3
what kind of membership 1 for corporate  or 2 for family: 1
The original price before discount is $, 69.0 after 20 percent discount 13.799999999999999 the total price will be $ 55.2

推荐阅读