首页 > 编程 > Python > 正文

Python 函数与变量--习题19,learn python the hard way

2019-11-08 01:33:11
字体:
来源:转载
供稿:网友
#coding=utf-8def Total_number_of_students(boys, girls):    PRint "There are %d boys within the environment." % boys    print "There are %d girls within the environment./n" % girls#运行方式一:数字print "Here's the most simple way to Operate this function by using numbers"Total_number_of_students(4, 5)#运行方式二:变量print "Here's another way to make the function works by working with arguments."boys = 10girls = 20Total_number_of_students(boys, girls)#运行方式三: 数学表达式print "Here's another way to import numbers to functions"Total_number_of_students(10 + 3, 10 + 4)#运行方式四:数字+变量print "Here's another way to make the function works."Total_number_of_students(boys + 4, girls + 5)#运行方式五:用户输入print "Here's the fifth way to make the function meaningful by raw_input:"boys = int(raw_input("how many boys are there within the environment?"))girls = int(raw_input("how many girls are there within the envrionment?"))Total_number_of_students(boys, girls)#运行方式六:用户输入2Note:1)def函数名是由:字符与下划线组成的。2)函数名后面紧跟着()3)()里面包含着参数,多个参数用逗号隔开,切不能使用重复的参数名。4)函数名后面的(),紧跟着:5)4个空格缩进后,编写该函数的代码。6)用户在终端输入时的数字也是字符串,应该使用X = int(raw_input()) 来处理
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表