think python学习心得-(4)有返回函数
        【摘要】  练习题 
6-1 
 
def compare(x,y): if x>y: return 1 elif x==y: return 0 else: return -1 a=[int(i) for i in raw_input('please input 2 number: ').split()]print compare(a[0],a[1])
 这里使用 
 
 
a=[...
    
    
    
    练习题
6-1
  
   - 
    
     
    
    
     
      def compare(x,y):
     
    
- 
    
     
    
    
      if x>y:
     
    
- 
    
     
    
    
      return 1
     
    
- 
    
     
    
    
      elif x==y:
     
    
- 
    
     
    
    
      return 0
     
    
- 
    
     
    
    
      else:
     
    
- 
    
     
    
    
      return -1
     
    
- 
    
     
    
    
      
     
    
- 
    
     
    
    
     
      a=[int(i) for i in raw_input('please input 2 number: ').split()]
     
    
- 
    
     
    
    
     
      print compare(a[0],a[1])
     
    
 
  
   - 
    
     
    
    
     
      a=[int(i) for i in raw_input('please input 2 number: ').split()]
     
    
- 
    
     
    
    
     
      语句可以实现用空格隔开的多个数据的输入,就像matlab中的向量一样,很好用!
     
    
 
  
   - 
    
     
    
    
     
      import math
     
    
- 
    
     
    
    
     
      def hypotenuse(x,y):
     
    
- 
    
     
    
    
      return math.sqrt(x**2+y**2)
     
    
- 
    
     
    
    
      
     
    
- 
    
     
    
    
     
      a=[int(i) for i in raw_input('please input 2 number: ').split()]
     
    
- 
    
     
    
    
      
     
    
- 
    
     
    
    
     
      print hypotenuse(a[0],a[1])
     
    
 
  
   - 
    
     
    
    
     
      def is_between(x,y,z):
     
    
- 
    
     
    
    
      if x<=y:
     
    
- 
    
     
    
    
      if y<=z:
     
    
- 
    
     
    
    
      return True
     
    
- 
    
     
    
    
      else:
     
    
- 
    
     
    
    
      return False
     
    
- 
    
     
    
    
      else:
     
    
- 
    
     
    
    
      return False
     
    
- 
    
     
    
    
      
     
    
- 
    
     
    
    
     
      a=[int(i) for i in raw_input('please input 3 number: ').split()]
     
    
- 
    
     
    
    
     
      print is_between(a[0],a[1],a[2])
     
    
 返回值是int类型的90
6-7
  
   - 
    
     
    
    
     
      def is_power(a,b):
     
    
- 
    
     
    
    
      if a%b==0:
     
    
- 
    
     
    
    
     
       a=a/b
     
    
- 
    
     
    
    
      if a>b:
     
    
- 
    
     
    
    
     
       is_power(a,b)
     
    
- 
    
     
    
    
      elif a==b:
     
    
- 
    
     
    
    
      print 'yes'
     
    
- 
    
     
    
    
      else:
     
    
- 
    
     
    
    
      print 'no'
     
    
- 
    
     
    
    
      else:
     
    
- 
    
     
    
    
      print 'no'
     
    
- 
    
     
    
    
     
      print 'Please number a and b'
     
    
- 
    
     
    
    
     
      x=int(raw_input())
     
    
- 
    
     
    
    
     
      y=int(raw_input())
     
    
- 
    
     
    
    
     
      is_power(x,y)
     
    
 
  
   - 
    
     
    
    
     
      flag=[]
     
    
- 
    
     
    
    
     
      def gcd(a,b):
     
    
- 
    
     
    
    
     
       m=min(a,b)
     
    
- 
    
     
    
    
      for i in range(m):
     
    
- 
    
     
    
    
      if a%(i+1)==0:
     
    
- 
    
     
    
    
      if b%(i+1)==0:
     
    
- 
    
     
    
    
     
       flag.insert=(i,i)
     
    
- 
    
     
    
    
     
      print 'please input a and b to get GCD'
     
    
- 
    
     
    
    
     
      x=int(raw_input())
     
    
- 
    
     
    
    
     
      y=int(raw_input())
     
    
- 
    
     
    
    
     
      gcd(x,y)
     
    
- 
    
     
    
    
     
      print flag
     
    
 
 
文章来源: zclhit.blog.csdn.net,作者:zclhit_,版权归原作者所有,如需转载,请联系作者。
原文链接:zclhit.blog.csdn.net/article/details/50970841
        【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
            cloudbbs@huaweicloud.com
        
        
        
        
        
        
        - 点赞
- 收藏
- 关注作者
 
             
           
评论(0)