2.
def lst(input):
lst2=[]
count=0
for i in range(0,len(input)):
if i %2!=0:
lst2.append(input[i])
return lst2
a=lst((2,9,29,36,9))
print(a) 3.
def pd(input):
if len(input)>5:
return True
else:
return False
a=pd((5,5,6,9,7))
print(a) 4.
def a(input):
if type(input)==list:
if len(input)>2:
return input[0],input[1]
else:
return ('请输入列表')
d=a(['小明','大明'])
print(d)
5.写函数,计算传入函数的字符串中, 数字、字母、空格 以及 其他内容的个数,并返回结果。
def func(s=""): # function
shuzi = 0
zimu = 0
kongge = 0
qita = 0
for c in s: # 循环字符串.拿到每个字符
if c.isdigit(): # 数字
shuzi += 1
elif c.isalpha():
zimu+=1
elif c == ' ':
kongge += 1
else:
qita += 1
return shuzi, zimu, kongge, qita
6.
def num(n1,n2):
if n1>n2:
return n1
elif n1<n2:
return n2
a=num(26,98)
print(a)
7.
def dic(dic):
for k,v in dic.items():
if len(v)>2:
dic[k]=v[0:2]
return dic
a=dic({1:'dsfgasdf',2:'sdfsdsd',3:'卡卡卡的双丰收'})
print(a)
8.
def list(input):
dic={}
if type(input)==type([]):
for i in range(0,len(input)):
dic[i]=input[i]
return dic
elif type(input)!=type([]):
return '请输入列表'
a=list([2,3,6,5,9,8])
print(a)
9.
def xx(姓名=input('姓名:'),性别=input('性别:'),年龄=input('年龄:'),学历=input('学历:')):
student_msg={}
student_msg['姓名']=姓名
student_msg['性别'] = 性别
student_msg['年龄'] = 年龄
student_msg['学历'] = 学历
return student_msg
a=xx()
print(a)
9.
def func(name, age,edu,sex ="男"):
f = open("student.msg", mode="a", encoding="utf-8")
f.write(name+"_"+str(age)+"_"+sex+"_"+edu+"\n")
f.flush()
f.close()
10.
def xx():
while True:
a=input('姓名:')
if a.lower() == 'q':
break
else:
student_msg={}
student_msg['姓名']=a
student_msg['性别'] = input('性别:')
student_msg['年龄'] = input('年龄:')
student_msg['学历'] = input('学历:')
return student_msg aa=xx()
print(aa)
11.
def ch(wjm,ynr,xnr):
import os
with open(wjm,'r',encoding='utf-8') as f1, open('a.txt','w',encoding='utf-8') as f2:
for i in f1.readlines():
a=i.replace(ynr,xnr)
f2.write(a)
os.remove(wjm)
os.rename('a.txt',wjm)
ch('4.txt','alex','sb')
12.
def dl(username,password):
count=0
while count<=3:
if username=='' and password=='':
return ('登录成功')
count=count+1
else :
return ('请重新输入:')
count+=1 a=dl(12563,'')
print(a)

python day09作业答案的更多相关文章

  1. python day10作业答案

    2.def func(*args): sum = 0 for i in args: sum=sum+int(i) return sum a=func(2,3,9,6,8) print(a) 3. a= ...

  2. python day08作业答案

    1. a f=open('11.txt','r',encoding='utf-8') a=f.read() print(a) f.flush() f.close() b. f=open('11.txt ...

  3. python day09作业

  4. python day07作业答案

    1. sum=0 a=input() for i in a: sum=sum+int(i)**3 if sum==int(a): print('水仙数') 2. lst=[100,2,6,9,1,10 ...

  5. python day06 作业答案

    1. count=1 while count<11: fen=input('请第{}个评委打分' .format( count)) if int(fen) >5 and int(fen) ...

  6. python day05 作业答案

    1. b.不可以 c.tu=("alex",[11,22,{"k1":"v1","k2":["age" ...

  7. python day04 作业答案

    1. 1) li=['alex','WuSir','ritian','barry','wenzhou'] print(len(li)) 2) li=['alex','WuSir','ritian',' ...

  8. python day02 作业答案

    1. (1).false   (2).false 2. (1).8  (2).4 3. (1).6  (2).3  (3).false (4).3   (5).true   (6).true  (7) ...

  9. 笔试 - 高德软件有限公司python问题 和 答案

    高德软件有限公司python问题 和 答案 本文地址: http://blog.csdn.net/caroline_wendy/article/details/25230835 by Spike 20 ...

随机推荐

  1. HDU - 4436sam裸题

    题意:给你多个数字串,求本质不同的子串和(去掉前导零) 题解:建广义sam,刚开始一直想的是用l来计算,发现前导零对l的影响根本消不掉,所以不会做= =,原来应该是直接用一个新的数组表示到当前有多少个 ...

  2. Python 向列表中添加元素

    向列表中添加元素 1.append tabulation1.append('紫霞') ['大圣', '天蓬', '卷帘', '紫霞', '紫霞', '青霞'] 2.insert tabulation1 ...

  3. 【其他】【navicat】【1】navicat导入txt文件中文乱码问题解决

    正文: TXT文件默认编码为ANSI,另存为编码为UTF-8的文本文件即可 备注: 1,一般需要导入的数据都是一张excel表,需要将excel表另存为“文本文件(制表符分隔)(*.txt)”保存类型 ...

  4. 数据结构与算法之PHP查找算法(二分查找)

    二分查找又称折半查找,只对有序的数组有效. 优点是比较次数少,查找速度快,平均性能好,占用系统内存较少: 缺点是要求待查表为有序表,且插入删除困难. 因此,折半查找方法适用于不经常变动而查找频繁的有序 ...

  5. python零碎知识点

    0.规范化 使用Ctrl+Alt+L可以将代码排列格式更加规范化 1.浮点数 1.23x109就是1.23e9或者12.3e8:0.000012可以写成1.2e-5 2.字符串 >>> ...

  6. HBase环境搭建、shell操作及Java API编程

    一. 1.掌握Hbase在Hadoop集群体系结构中发挥的作用和使过程. 2.掌握安装和配置HBase基本方法. 3.掌握HBase shell的常用命令. 4.使用HBase shell命令进行表的 ...

  7. [CodeForces - 197A] A - Plate Game

    A - Plate Game You've got a rectangular table with length a and width b and the infinite number of p ...

  8. 【转】vue中动态设置meta标签和title标签

    因为和原生的交互是需要h5这边来提供meta标签的来是来判断要不要显示分享按钮,所有就需要手动设置meta标签,标题和内容 //router内的设置 { path: '/teachers', name ...

  9. SecureCRT sftp上传文件报错:put: failed to upload xxx 拒绝访问

    1.问题 使用sftp上传文件时报错:put: failed to upload xxx 拒绝访问.类似下图所示: 2.原因 造成这个问题的原因可能有两个,一是要上到的那个目录剩余磁盘空间不足,二是打 ...

  10. Qt之获取子部件

    Qt5.10 QList<QObject*> list_children = this->children(); for(int i=0;i<list_children.siz ...