zoukankan      html  css  js  c++  java
  • ex21 函数可以返回某些东西

    ex21

    在创建函数之后,通过 return 可以让函数返回一些值。

    #-*- coding: UTF-8 -*- 
    def add(a,b):
     print"Adding %d + %d." % (a,b)#注意格式啊格式!!
     return a + b
     
    def subtract(a,b):
     print"SUBTRACTING %d -%d" %(a,b)
     return a-b
     
    def multiply (a,b):
     print "MULTIPLY %d*%d" %(a,b)
     return a*b
     
    def divide (a,b):
     print "DIVIDING %d/%d"%(a,b)
     return a/b
     
     
    print "Let's do some match with just functions."
    
    age = add(30,5)
    height = subtract(78,4)
    weight = multiply(90,2)
    iq = divide(100,2)
    
    print "Age:%d,Height:%d,Weight:%d,IQ:%d" %(age,height,weight,iq)
    
    print "Here is a puzzle."
    
    what = add(age,subtract(height,multiply(weight,divide(iq,2))))#自内而外进行打印
     
    print "That becomes",what,"Can you do it by hand?"
    
    #通过正常的方法实现了puzzle里边的功能
    divd = divide(iq,2)
    
    multip = multiply(weight,divd)
    
    subsrt = subtract(height,multip)
    
    ad = add(age,subsrt)
    print "That becomes",what,"Can you do it by hand?"
    
     
  • 相关阅读:
    登录注册功能
    29-----BBS论坛
    linux笔记
    nginx,uwsgi发布web服务器
    linux常用服务部署
    linux系统基础优化及常用命令
    linux基本操作命令
    linux命令
    linux基础
    阿里云服务器搭建
  • 原文地址:https://www.cnblogs.com/dingtou00/p/7708342.html
Copyright © 2011-2022 走看看