这是我的代码:
for i in range(1,76):
input('Enter name for guest'+str( i)+': ')
ages=int(input('Enter age for guest '+str(i)+':'))
for x in range(20,30) in list(ages):
print('Number of people in 20s is ' +str(x) )
如何将结果列入清单并打印出20多岁的人数?谢谢。
答案 0 :(得分:2)
这是你想要的吗?
ages = []
for i in range(1,76):
input('Enter name for guest'+str( i)+': ')
ages.append(int(input('Enter age for guest '+str(i)+':')))
n = len([a for a in ages if 20 <= a < 30])
print('Number of people in 20s is ' + str(n) )