0% found this document useful (0 votes)
15 views

Lists Py 2

The document defines several functions: get_rounds returns a list with 3 consecutive numbers; concatenate_rounds concatenates two lists; list_contains_round checks if a list contains a number; card_average calculates the average of a list; approx_average_is_average checks if the average equals the middle element of an odd-length list; average_even_is_average_odd checks if the average of even elements equals the average of odd elements; maybe_double_last doubles the last element if it is 11; and prints the result of calling approx_average_is_average on a sample list.

Uploaded by

tejasri1.g
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Lists Py 2

The document defines several functions: get_rounds returns a list with 3 consecutive numbers; concatenate_rounds concatenates two lists; list_contains_round checks if a list contains a number; card_average calculates the average of a list; approx_average_is_average checks if the average equals the middle element of an odd-length list; average_even_is_average_odd checks if the average of even elements equals the average of odd elements; maybe_double_last doubles the last element if it is 11; and prints the result of calling approx_average_is_average on a sample list.

Uploaded by

tejasri1.g
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

def get_rounds(n):

return ([n,n+1,n+2])
pass

def concatenate_rounds(r1, r2):


return r1+r2
pass

def list_contains_round(r, n):


if n in r:
return True
else:
return False
pass

def card_average(h):
x=0
for i in h:
x+=i
x=x/len(h)
return x
pass

def approx_average_is_average(h):
if card_average(h) == h[len(h)//2]:
return True
else:
return False
pass

def average_even_is_average_odd(h):
x,y=0,0
m,n=0,0
for i in range(len(h)):
if i==0:
x+=h[0]
m+=1
elif i==1:
y+=h[1]
n+=1
elif i%2==0:
x+=h[i]
m+=1
else:
y+=h[i]
n+=1
if x/m==y/n:
return True
else:
return False
pass

def maybe_double_last(h):
if h[-1]==11:
h[-1]=22
return h
pass

print(approx_average_is_average([2,3,4,8,8]))

You might also like