def fun1(a): s=[] for i in range(len(a)): if i%2 == 1: s.append(a[i]) else: pass return a lst=[11,22,33,44,55] print(lst)
def f1(p): print("判断用户传入的对象(字符串、元祖、列表)长度是否大于6:") if len(p) >=5: return True else: return False answer=input("请输入:") print(f1(answer))
def f1(p): for a,b in p.items(): b=str(b) if len(b) >2: p[a] = b[0:2] print(p) res={'name':'小华','age':20,'sex':'男'} f1(res)
s=input("请输入一个字符串:") def fun1(s): shuzi=zimu=kongge=qita=0 for i in range(len(s)): if (s[i] >= 'a' and s[i] <= 'z') or (s[i] >= 'A' and s[i] <= 'Z'): shuzi +=1 elif (s[i] >= '0' and s[i] <= '9'): zimu +=1 elif (s[i] ==' 'or s[i]==' '): kongge +=1 else: qita +=1 return (shuzi,zimu,kongge,qita) print(fun1(s))
def max(): a=input("输入第一个数字:") b=input("输入第二个数字:") if a >=b: return (a) else: return (b) print(max())
a=input('输入第一个数字:') b=input('输入第二个数字:') c=input('请输入第三个数字:') sum=float(a)+float(b)+float(c) print("多个数之和为:",sum)
def fun1(*nums): lst=[] for s in nums: for s1 in s: lst.append(s1) return lst sum=fun1([1,2,3], (22,33)) print(sum)
def fun1(**kwargs): return kwargs s=fun1(**{'one':1},**{'two':2}) print(s)
import math#print("计算一元二次ax^2+Bx+c=0") def quadratic(a,b,c): t=math.sqrt(pow(b,2)-4*a*c) if(pow(b,2)-4*a*c)>0: return (-b+t)/(2*a),(-b-t)/(2*a) elif(pow(b,2)-a*a*c)==0: return (-b+t)/(2*a) else: return print(quadratic(1,2,0))#a,b,c的值可以变换