|
2鱼币
[code]class Judge():
print("--------游乐园价票系统--------")
def __index__(self):
while True:
try:
self.days = int(input("请输入今天是星期几(1-7):"))
days = self.days
if days in range(1,8):
break
else:
print(f"星期{days}有误!")
continue
except (TypeError,ValueError):
print("输入的内容有误,请重新输入一个数字:")
def ticket(self):
while True:
try:
self.adults = int(input("请输入需要几张成人票:"))
self.children= int(input("请输入需要几张儿童票:"))
adults = self.adults
children= self.children
return adults,children
except (TypeError,ValueError):
print("输入错误,请重新输入:")
class Charge:
def __init__(self):
a = Judge()
pirce = 100
adult,child = Judge.ticket()
aprice = adult * price
cprice = child * price
if Judge.days in range(6,8):
print(f"当前的成人价票为{aprice*1.2},当前儿童价票为{cprice*1.2*0.5},总共票价为{aprice*1.2+cprice*1.2*0.5}")
else:
print(f"当前成人价票为{aprice},当前儿童价票为{cprice*0.5},总票价为{aprice+cprice*0.5}")
c = Charge()
问题1,没明白
问题2,没能重现
你的程序有错误,帮你改正了。
- class Judge():
- print("--------游乐园价票系统--------")
- def __init__(self):
- while True:
- try:
- self.days = int(input("请输入今天是星期几(1-7):"))
- days = self.days
- if days in range(1,8):
- break
- else:
- print(f"星期{days}有误!")
- continue
- except (TypeError,ValueError):
- print("输入的内容有误,请重新输入一个数字:")
- def ticket(self):
- while True:
- try:
- self.adults = int(input("请输入需要几张成人票:"))
- self.children= int(input("请输入需要几张儿童票:"))
- adults = self.adults
- children= self.children
- return adults,children
- except (TypeError,ValueError):
- print("输入错误,请重新输入:")
- class Charge:
- def __init__(self):
- a = Judge()
- price = 100
- adult,child = a.ticket()
- aprice = adult * price
- cprice = child * price
- if a.days in range(6,8):
- print(f"当前的成人价票为{aprice*1.2},当前儿童价票为{cprice*1.2*0.5},总共票价为{aprice*1.2+cprice*1.2*0.5}")
- else:
- print(f"当前成人价票为{aprice},当前儿童价票为{cprice*0.5},总票价为{aprice+cprice*0.5}")
- c = Charge()
复制代码
|
最佳答案
查看完整内容
问题1,没明白
问题2,没能重现
你的程序有错误,帮你改正了。
|