File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #Write a program that prompts the user to enter a series of age (number) to be inserted in a list named age.
2+ The size of the list is 10. The program then , will evaluate the status of ‘child ’ or ‘adult ’ based on the user input .
3+ If the age is less than or equal to 18 , the program will store it in the children list .
4+ However , if the age is greater than 19 , the program will store it in the adult list .
5+ The program has to display the content of the three lists .
6+ The program also has to calculate and display the total number of elements in all of the lists . Name the Python file as age .py .
7+
8+
9+ -
10+
11+ total = 0
12+ age = []
13+
14+ a = (input ('Enter age: ' ))
15+
16+ while a != '' :
17+ age .append (int (a ))
18+ a = input ()
19+
20+
21+ for i in age :
22+ if i <= 0 :
23+ print ('This age is not defined' )
24+ elif i in range (1 , 18 ):
25+ print ('Children' )
26+
27+ elif i >= 19 :
28+ print ('Adult' )
29+
30+
31+
32+ print (' ' )
33+ print ('List of number you just input is' , age )
34+
35+ print (' ' )
36+ Sum = sum (age )
37+ print ('The total sum of numbers in this list are' , Sum )
38+
39+ print (' ' )
40+ print ('There are' , len (age ), 'elements in the input' )
You can’t perform that action at this time.
0 commit comments