python day09作业答案
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作业答案的更多相关文章
- 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= ...
- 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 ...
- python day09作业
- 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 ...
- python day06 作业答案
1. count=1 while count<11: fen=input('请第{}个评委打分' .format( count)) if int(fen) >5 and int(fen) ...
- python day05 作业答案
1. b.不可以 c.tu=("alex",[11,22,{"k1":"v1","k2":["age" ...
- python day04 作业答案
1. 1) li=['alex','WuSir','ritian','barry','wenzhou'] print(len(li)) 2) li=['alex','WuSir','ritian',' ...
- 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) ...
- 笔试 - 高德软件有限公司python问题 和 答案
高德软件有限公司python问题 和 答案 本文地址: http://blog.csdn.net/caroline_wendy/article/details/25230835 by Spike 20 ...
随机推荐
- linux的越墙方法
.首先要安装openSSH, Ubuntu缺省没有安装SSH Server,使用以下命令安装: sudo apt-get install openssh-server 但是系统有时候会出现E类错误,无 ...
- 11204RAC-dbca建库脚本
SET VERIFY OFFconnect "SYS"/"&&sysPassword" as SYSDBAset echo onspool /u ...
- [LightOJ 1265] Island of Survival
Island of Survival You are in a reality show, and the show is way too real that they threw into an i ...
- Winform下有关控件焦点问题
工作中遇到这样一个需求,根据控件焦点弹出对应的代码帮助窗体.比如界面上,有两个TextBox需要进行代码帮助功能的实现. 首先是绑定主窗体的代码帮助事件. 首先要给代码帮助这个按钮绑定事件: priv ...
- hdu-1176免费馅饼
免费馅饼 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- Oracle RAC管理及维护命令详解
Oracle Clusterware的命令集可以分为以下4种: 节点层:osnodes 网络层:oifcfg 集群层:crsctl, ocrcheck,ocrdump,ocrconfig 应用层:sr ...
- Vue 使用 vuelidate 实现表单验证
表单验证的应用场景十分广泛,因为网站对用户输入内容的限制是非常必要的. 在vue中,我们使用vuelidate方便地实现表单验证. 官方文档在这里https://monterail.github.io ...
- [LeetCode] 111. Minimum Depth of Binary Tree ☆(二叉树的最小深度)
[Leetcode] Maximum and Minimum Depth of Binary Tree 二叉树的最小最大深度 (最小有3种解法) 描述 解析 递归深度优先搜索 当求最大深度时,我们只要 ...
- js正则表达式 replace替换url的参数
/* 定义替换对象键值 */var setReferArgs = function(){ var referArgs = new Object(); referArgs['#userID\ ...
- python3线程启动与停止
转自: https://blog.csdn.net/weixin_38125866/article/details/76795462 https://www.cnblogs.com/lcchuguo/ ...