Home > other >  Save the children, to see where is wrong
Save the children, to see where is wrong

Time:10-27

What went wrong

Write functions: randomly generated contains a list of n integers, return a tuple, one of the first element as the mean value of all parameters, the other elements for all parameters in the integer greater than the average,
Import the random
Def func (n) :
List_a=[random randint (0100) for I in range (n)]
Print (list_a)
S=0
For I in list_a:
S=s + I
Averge=s/n
B=a tuple (averge,)
C=[]
For I in list_a:
If i> Averge:
C.a. ppend (I)
D=the tuple (c)
M=b + d
Return m

N=int (input (" please enter an integer: "))
Func (n)
Print (func (n))

Traceback (the most recent call last) :
The File "C://1.3.4 python experiment. Py", line 19, in & lt; module>
Func (n)
The File "C://1.3.4 python experiment. Py", line 9, in func
B=a tuple (averge,)
TypeError: 'float' object is not iterable

CodePudding user response:

 import random 

Def func (n) :
List_a=the random sample (range (101), n)
Avg=sum (list_a)/n
Return (avg) + the tuple (I for I list_a in the if I & gt; Avg)

Rec=func (10)
Print (rec)
  • Related