| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 12345 | Python_mooc_1 |
|
| 12346 | Python_mooc_2 |
|
| 12347 | Python_mooc_3 |
|
Description
Write a Python function to compute the average of a sequence of numbers after
discarding m lowest and n highest scores. If the sequence is empty before or after
cropping, then return None
''' you should use the template of following.'''
Input
[3, 15, 13, 9, 11, 7, 5]
Output
>>> CroppedAverage(L) # works like a regular average
9.0
>>> CroppedAverage(L, dropLow=2, dropHigh=1) # drop 3, 5, 15
10.0
>>> CroppedAverage(L, dropLow=3, dropHigh=4) # drop all
None
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Define a subclass of tuple such that it supports the __contains__ special method
(corresponding to the in operator in reverse) that works similar to the str version.
For your information,

But tuple does not support slice containment:

Define a subclass of tuple named STuple such that containment works for both
elements and slices:

''' you should use the template of following.'''
import ast
class STuple(tuple):
'''inherit constructor'''
def __contains__(self, item):
#coding on here
#coding on here
#coding on here
if __name__ == '__main__':
pat = ast.literal_eval(input()) # pattern input
testSeq = ast.literal_eval(input()) # test case input
for p in pat:
for t in testSeq:
print(f'{p} in STuple{t} =', p in STuple(t))
Input
['o', 's', ('s', 'c', 'h'), (), ('o', 'o')]
[(), ('s', 'c', 'h', 'o', 'o', 'l'), ('s', 'c', 'h'), ('k', 'o' 'o', 'l'), ('o', 'o', 'l')]
Output
o in STuple() = False
o in STuple('s', 'c', 'h', 'o', 'o', 'l') = True
o in STuple('s', 'c', 'h') = False
o in STuple('k', 'oo', 'l') = False
o in STuple('o', 'o', 'l') = True
s in STuple() = False
s in STuple('s', 'c', 'h', 'o', 'o', 'l') = True
s in STuple('s', 'c', 'h') = True
s in STuple('k', 'oo', 'l') = False
s in STuple('o', 'o', 'l') = False
('s', 'c', 'h') in STuple() = False
('s', 'c', 'h') in STuple('s', 'c', 'h', 'o', 'o', 'l') = True
('s', 'c', 'h') in STuple('s', 'c', 'h') = True
('s', 'c', 'h') in STuple('k', 'oo', 'l') = False
('s', 'c', 'h') in STuple('o', 'o', 'l') = False
() in STuple() = True
() in STuple('s', 'c', 'h', 'o', 'o', 'l') = True
() in STuple('s', 'c', 'h') = True
() in STuple('k', 'oo', 'l') = True
() in STuple('o', 'o', 'l') = True
('o', 'o') in STuple() = False
('o', 'o') in STuple('s', 'c', 'h', 'o', 'o', 'l') = True
('o', 'o') in STuple('s', 'c', 'h') = False
('o', 'o') in STuple('k', 'oo', 'l') = False
('o', 'o') in STuple('o', 'o', 'l') = True
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Write a recursive function to find the largest integer in a tuple that can contain
integers, other tuples that contain integers (or other tuples alike). For example,
$ python3 -I maxInTuple.py

You may assume that tuples are non-empty, but it may contain minimally one
member (int or another tuple).
''' you should use the template of following.'''
import ast
def max_in_tuple(t):
#Coding on here
#Coding on here
#Coding on here
if __name__ == '__main__':
L = ast.literal_eval((input()))
for testcase in L:
print(f'max_in_tuple({testcase}) = {max_in_tuple(testcase)}')
Input
[(1, 5, (2, 7, (14, 6)), (9, 12)), (3, (7,), -5)]
Output
max_in_tuple((1, 5, (2, 7, (14, 6)), (9, 12))) = 14
max_in_tuple((3, (7,), -5)) = 7