0

Поочему не работает код "Билетная касса"?

data = { "100-90": 25, "42-01": 48, "55-09": 12, "128-64": 71, "002-22": 18, "321-54": 19, "097-32": 33, "065-135": 64, "99-043": 80, "111-99": 11, "123-019": 5, "109-890": 72, "132-123": 27, "32-908": 27, "008-09": 25, "055-967": 35, "897-99": 44, "890-98": 56, "344-32": 65, "43-955": 59, "001-233": 9, "089-111": 15, "090-090": 17, "56-777": 23, "44-909": 27, "13-111": 21, "87-432": 15, "87-433": 14, "87-434": 23, "87-435": 11, "87-436": 12, "87-437": 16, "94-121": 15, "94-122": 35, "80-089": 10, "87-456": 8, "87-430": 40 } age = int(input()) c=data.values() x1=len([i for i in c if i>age]) y1=len([q for q in c if q<age]) adult1=20*x1 child1=5*y1 all1=adult1+child1 x2=len([i for i in c if i>18]) y2=len([q for q in c if q<18]) adult2=20*x2 child2=5*y2 all2=adult2+child2 procent=((all1-all2)/all2)*100 print(int(procent))

15th Oct 2021, 2:02 AM
Илья
Илья - avatar
5 Answers
+ 1
data = { "100-90": 25, "42-01": 48, "55-09": 12, "128-64": 71, "002-22": 18, "321-54": 19, "097-32": 33, "065-135": 64, "99-043": 80, "111-99": 11, "123-019": 5, "109-890": 72, "132-123": 27, "32-908": 27, "008-09": 25, "055-967": 35, "897-99": 44, "890-98": 56, "344-32": 65, "43-955": 59, "001-233": 9, "089-111": 15, "090-090": 17, "56-777": 23, "44-909": 27, "13-111": 21, "87-432": 15, "87-433": 14, "87-434": 23, "87-435": 11, "87-436": 12, "87-437": 16, "94-121": 15, "94-122": 35, "80-089": 10, "87-456": 8, "87-430": 40 } age = int(input()) def price(x): price = 0 for val in data.values(): if val >= x: price = price + 20 else: price = price + 5 return price print(int(((price(age) - price(18)) / price(18)) * 100))
19th Oct 2021, 7:33 AM
Maksim Raith
Maksim Raith - avatar
0
from functools import reduce data={ "100-90": 25, "42-01": 48, "55-09": 12, "128-64": 71, "002-22": 18, "321-54": 19, "097-32": 33, "065-135": 64, "99-043": 80, "111-99": 11, "123-019": 5, "109-890": 72, "132-123": 27, "32-908": 27, "008-09": 25, "055-967": 35, "897-99": 44, "890-98": 56, "344-32": 65, "43-955": 59, "001-233": 9, "089-111": 15, "090-090": 17, "56-777": 23, "44-909": 27, "13-111": 21, "87-432": 15, "87-433": 14, "87-434": 23, "87-435": 11, "87-436": 12, "87-437": 16, "94-121": 15, "94-122": 35, "80-089": 10, "87-456": 8, "87-430": 40 } age=int(input("Enter age : ")) data2=[] for key,value in data.items(): data2.append(value) x=[a for a in data2 if a>age] y=[a for a in data2 if a<age] adult=list(map(lambda x:x*20,x)) child=list(map(lambda x:x*5,y)) a_ll=sum(adult)+sum(child) x2=[a for a in data2 if a>18] y2=[a for a in data2 if a<18] adult2=list(map(lambda x:x*20,x2)) child2=list(map(lambda x:x*5,y2)) a_ll2=sum(adult2)+sum(child2) procent=((a_ll-a_ll2)/a_ll2)*100 print(int(procent))
16th Oct 2021, 10:46 PM
Jasy Fabiano
Jasy Fabiano - avatar
0
This don't work too
17th Oct 2021, 1:11 PM
Илья
Илья - avatar
0
А вот так работает?
19th Oct 2021, 7:33 AM
Maksim Raith
Maksim Raith - avatar
0
Спасибо. Всё работает.
19th Oct 2021, 9:24 PM
Илья
Илья - avatar