lambda sum = lambda x,y : x + y print(sum(3,3),type(sum)) 默认参数 def prints(str,times = 2) : print(str*times) prints("Tree",3) 变长参数 def sums(*a): res = 0 for i in a: res += i return res print(sums(1,2,3,4,5)) return def swap(a,b): return b,a print…
p121: *题4.1:猜数字游戏.在程序中预设一个0~9之间的整数,让用户通过键盘输入所猜的数,如果大于预设的数,显示“遗憾,太大了!”:小于预设的数,显示“遗憾,太小了!”,如此循环,直至猜中该数,显示“预测N次,你猜中了!”,其中N是用户输入数字的次数. 源代码: from random import*y=5n=1m=Falsewhile(m==False): x=eval(input("请输入您猜想的数字:")) try: if(x>y): …
天天向上 dayup,dayfactor = 1.0,0.01 for i in range(365): if i % 7 in [6,0]: dayup = dayup*(1-dayfactor) else: dayup = dayup*(1+dayfactor) print("{:.2f}".format(dayup)) 天天向上2 def dayUP(df): dayup = 1.0 for i in range(365): if i % 7 in [6,0]: dayup =…