python小算法!

def monkey_trouble(a_smile,b_smile):
  if a_smile==b_smile:
      return True
  else:
      return False

def sum_double(a,b):
  if a==b:
      sum=(a+b)*2
      return sum
  else:
      sum=a+b
      return sum

def diff21(n):
    if n>21:
        return (n-21)*2
    if n<=21:
        return 21-n

def parrot_trouble(talking,hour):
    if talking is True  and (hour<7 or hour>=21):
        return True
    else:
        return False

def makes10(a,b):
    if  a==10 or b==10:
        return True
    elif a+b==10:
        return True
    else:
        return False

def near_hundred(n):
    if n>=90 and n<=110:
        return True
    elif n>=190 and n<=210:
        return True
        
    else:
        return False

def pos_neg(a,b,negative):
    if a >0 and b<0 and negative is False:
        return True
    elif a<0 and b>0 and negative is False:
        return True
    elif a<0 and b<0 and negative is True:
        return True
    else:
        return False

def not_string(str):
    if len(str)>=3 and str[:3]=='not':
        return  str
    else:
        return 'not '+str

def missing_char(str,n):
    if len(str)<=n:
        return str
    else:
        str=str[0:n]+str[n+1:]
        return str

def front_back(str):

    n=len(str)
    if n==1:
        return str
    return str[n-1:]+str[1:n-1]+str[0:1]

def front3(str):
    return str[0:3]*3

http://codingbat.com/prob/p118366

def string_splosion(str):
    result=""
    i=1
    b=len(str)
    for j in range(0,b):

        result=result+str[o:j]
    
    return result


你可能感兴趣的:(算法,python)