输入1-12 的数字,返回 月份简称
def Month(number):
if 1 <= number <= 12:
if number == 1:
return "Jan"
if number == 2 :
return "Feb"
if number == 3:
return "Mar"
if number == 4:
return "Apr"
if number == 5:
return "May"
if(number == 6):
return "Jun"
if number == 7:
return "Jul"
if(number == 8):
return "Aug"
if number == 9:
return "Sept"
if number == 10:
return "Oct"
if number == 11:
return "Nov"
if number == 12:
return "Dec"
else:
return "Invalid Number"
输入坐标值,判断是第几象限
def Quadrant(x, y):
if x<0:
if y<0:
return 'III'
if y>0:
return 'II'
if y==0:
return 'Not in any quadrant'
elif x==0:
return 'Not in any quadrant'
else:
if y<0:
return 'IV'
if y>0:
return 'I'
if y==0:
return 'Not in any quadrant'
输入年份,判断是否是闰年,(1)不能整除100 时能整除4的 (2)可以整除100同时整除400
def isLeapYear(y):
# YOUR CODE HERE
if y%100 == 0:
if y%400 == 0:
return True
else:
return False
elif y%4 == 0:
return True
else:
return False
raise NotImplementedError()
计算X和Y之间的奇数的和
def sumOdds(x, y):
# YOUR CODE HERE y要>x 求和
if(y>=x):
sum = 0
for i in range(x,y+1):
if i%2 == 1:
sum += i
return sum
else:
return 0
# raise NotImplementedError()
输入X,返回不小于X的最小素数
def nextPrime(x):
# YOUR CODE HERE
while True:
if isPrime(x):
return x
x+=1
def isPrime(x):
if x == 1:
return False
else:
for i in range(2,x):
if x%i == 0:
return False
return True
计算X和Y中完全平方数的个数
def perfectSquares(x, y):
# YOUR CODE HERE 4可以是2的平方,比数本生小0到x,如果符合某一数的平方,return 0,要求x<y,count+1
if x>y:
return 0
else:
count = 0
for i in range(x,y+1):
if((i**0.5)%1)==0:
count+=1
return count