2016_8_22
随便练练手
ac code
# -*- coding: utf-8 -*-
"""
Spyder Editor
author hanzy
This is a temporary script file.
"""
def a1(num):
sum1 = 0
flag = 0
for i in range(1,len(num),1):
if (num[i] % 5==0) and (num[i] % 2==0):
sum1 = sum1 + num[i]
flag = 1
if flag == 1:
return sum1
else:
return "N"
def a2(num):
num2 = []
sum1 = 0
flag = 0
for i in range(1,len(num),1):
if (num[i] % 5==1):
num2.append(num[i])
flag = 1
for i in range(len(num2)):
if i%2==0:
sum1 = sum1 + num2[i]
else:
sum1 = sum1 - num2[i]
if flag == 1:
return sum1
else:
return "N"
def a3(num):
count = 0
flag = 0
for i in range(1,len(num),1):
if (num[i] % 5==2):
count += 1
flag = 1
if flag == 1:
return count
else:
return "N"
def a4(num):
sum1 = count = 0
flag = 0
for i in range(1,len(num),1):
if (num[i] % 5 == 3):
sum1 = sum1 + num[i]
flag = 1
count += 1
if flag == 1:
return sum1*1.0/count
else:
return 'N'
def a5(num):
numlist = []
flag = count = 0
for i in range(1,len(num),1):
if (num[i] % 5 == 4):
numlist.append(num[i])
flag = 1
count += 1
numlist.sort()
if flag == 1:
return numlist[count-1]
else:
return "N"
if __name__ == "__main__":
numlist = raw_input()
num = []
num1 = numlist.split(' ')
for i in range(len(num1)):
num.append(int(num1[i]))
if(a4(num) != 'N'):
print a1(num),a2(num),a3(num),'%.1f'%a4(num),a5(num)
else:
print a1(num),a2(num),a3(num),'N',a5(num)