Program change (5) python median https://qiita.com/kaizen_nagoya/items/2f02d5f8af808e322e3c
Encountered while working trying to check with docker.
Installed with apt install python2.7 with docker. Edit with vi
# python2.7 median.py
File "median.py", line 4
SyntaxError: Non-ASCII character '\xe8' in file median.py on line 4, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
The contents of the python file
median.py
# https://qiita.com/manzyun/items/833ae7fba582d899c618
data = [100, 300, 423, 328, 516, 412]
data.sort() # **?~E large?~K**
if len(data) % 2 == 0: # ?~C??~B??~C~H?~A??~A?| ?~A??~U??~A??~G?~U??~C??~A??~~
U??~H??~Z
# ?~A??~U??~A??~A~W?~A~_
m1 = len(data) / 2
m2 = (len(data) / 2) + 1
# ?~U??~U??~A??~I?~O~[?~A~W?~A??~M place?~P~H?~B~O?~A~[
m1 = int(m1) - 1
m2 = int(m2) - 1
print(data[m1] + data[m2]) / 2
else:
# ?~G?~U??~A??~A~W?~A~_
m = (len(data) + 1) / 2
m = int(m) - 1
print(data[m])
Recommended Posts