print(’\033[1;37;42m 输入验证码 \033[0m’)
#print(chr(0xf045),’\033[1;47;34m 输入验证码 \033[0m’)
#print(‘’)
#print(’| python团队 |’)
#print(’| MMMM |’)
#print('’)
#a=100
#b=5
#print(a*b)
#fp = open(r’E:\BaiduNetdiskDownload\python Files\第六章.txt’,‘a+’) #打开文件
#print(‘第六章’,file = fp) #输出到文件中
#fp.close() #关闭文件
#1.错误的方式:
#import datetime # //调用日模块
#print(‘当前年份:’+str(2019.2019.now().year)) #//输出当前年份,当前年为2018年,输出2018
#输出当前日期和时间,如2018-11-20 15:30:25, 注意代码中的单引号、字母大小写、不能写错
#print(‘当前日期时间:’+2019-5-12.22:16:25.now().strftime(’%Y-%m-%d %H:%M:%S’))
#2.正确的方式:
#import datetime
#print(‘2019:’+str(datetime.datetime.now().year))
#2019-6-18 15:30:23,
#print(‘2019-6-18 15:30:23:’+datetime.datetime.now().strftime(’%Y-%m-%d %H:%M:%S’))
#import getpass
#variable =input(‘提示文字’)
#tip = input(‘请输入文字:’)
#num=int(input(‘请输入您的幸运数字:’))
#name=input(‘输入字符:’)
#print(name+‘的ASCII码为:’,ord(name))
#题目:使用input()函数计算年龄
#import datetime
#imyear=input(‘请输入您的出生年份:’)
#nowyear=datetime.datetime.now().year
#age=nowyear-int(imyear)
#print(‘您的年龄为:’+str(age)+’(岁)’)
#根据计算的年龄所处的年龄段,判断标准是根据联合国组织给出的新年龄分段判定标准
#if age<18:
print(‘您现在为未成年人’)
#if age>=18 and age<66:
#print(‘您现在为青年人’)
#if age>=66 and age<80:
#print(‘您现在为中年人’)
#if age>=80:
#print(‘您现在为老年人’)
#print(format(‘明日’,’ >20’))
#print(format(‘明日’,’ <20’))
#print(format(‘明日’,’ ^20’))
#money_all=56.12+252.56+563.25+562.5 #累加总计金额
#money_all_str=str(money_all) #转换为字符串
#print(‘商品总金额为:’+ money_all_str)
#money_real=int(money_all) #进行摸零处理
#money_real_str=str(money_real) #转换为字符串
#print(‘实际收金额为:’+ money_real_str)
#import datetime
#print(datetime.date.today())
#print(datetime.date.today()+datetime.timedelta(days=5))
#print(“M”*10)
#python=95
#english=92
#c=89
#sub=python-english
#avg=(python +english +c )/3
#print(“python课程和英语课程的分数差:”+str(sub)+“分\n”)
#print(“3门课程的平均分:”+str(avg)+“分”)
“”"
a=1
b=2
a=a+b
print(a)
a+=b
print(a)
a=a-b
print(a)
a-=b
print(a)
“”"
“”"
python=95
englist=92
c=89
print(“python=”+str(python)+“englist=”+str(englist)+“c=”+str©+"\n")
print(“python<englist的结果:”+str(python<englist))
“”"
“”"
print(“12&8=”+str(12&8))
print(“4|8=”+str(4|8))
print ("3132="+str(3132))
print(“123="+str(123))
“””
“”"
import random
list=[1,2,3,4,5,6]
random.shuffle(list) #将数字1-6打乱
print(list)
“”"
“”"
import random
list=[1,2,3,4,5,6,7,8,9,10,11]
print(random.sample(list,5)) #从数字0-11中随机数输出5个数字
“”"
“”"
import random
print(random.randrange(1,10))
“”"
“”"
print(",".join([“德国”,“法国”,“美国”,“俄罗斯”]))
a=“德国”
b=“法国”
c=“美国”
d=“俄罗斯”
list=[a,b,c,d]
m="".join(list) #直接连接字符串
n=" “.join(list)
print(m)
print(n)
“””
“”"
nba =[“俄罗斯”,“英国”,“中国”,“美国”]
print(“中国” not in nba)
“”"
“”"
untitle = [“中国”,28,“美国”,“日本”,[“爬虫”,“python”,“哈哈”]]
print(untitle)
untitle[3]=“俄罗斯”
print(untitle)
“”"
“”"
untitle = [“中国”,28,“美国”,“日本”,[“爬虫”,“python”,“哈哈”]]
value=“美国”
if untitle.count(value) >0:
untitle .remove(value)
print(untitle)
player = [“中国”,“日本”,“美国”,“日本”,“爬虫”,“python”,“哈哈”]
num=player.count(“日本”)
print(num)
number =(i for i in range(4)) #生成生成器对象
for i in number: #遍历生成器对象
print(i,end=" ") #输出每个元素的组
print(tuple(number)) #转化为元组输出
password = 0
i = 1
while i < 7:
num = input(“请输入一位数字密码!”)
num = int(num)
if num == password :
print(“密码输入正确,正在进入系统!”)
else:
print(“密码输入错误,已经输错”,i,“次”)
i += 1
if i==7:
print(“密码错误六次,请与发卡行联系!!!”)
total = 99
for number in range(1,100):
if number %7==0:
continue
else:
string =str(number)
if string.endswith(“7”):
continue
total -= 1
print(“从1数到99拍腿”,total,“次”)
str2 =’@明日科技.@.’
print(‘原字符串str2:’+str2+’。’)
print(‘字符串:’+str2.strip(’@.’)+’。’)
class Geese:
“”""""
def init(self,beak):
print(“我是大雁类”)
print(beak)
beak_1=“你好”
WildGoose=Geese(beak_1)
chang=input(“chang:”)
num_gao=0
gao = input(“gao:”)
while num_gao<int(gao):
num_chang = 0
while num_chang<int(chang):
print("#",end="")
num_chang+=1
print()
num_gao+=1
for i in range(1,10):
for j in range(1,i+1):
print("%d*%d=%2d"%(i,j,i*j),end="\t")
print()
for i in range(1,11):
for j in range(1,11):
print("#",end=" “)
print(”#")
“”"
tupleabs = [12.45,0,-19.69]
for i in tupleabs:
print(abs(i))
def aabs(value1,value2):
return abs(value1*value2)
print(aabs(12.96,8.2))
print(aabs(10,-10))
def getDivmod(A,N):
while N >= 0:
sn = str(N)
sa = str(A)
result = [“divmod({0},{1}):”.format(sn,sa),str(divmod(N,A))]
print("".join(result))
N = N - 1
getDivmod(3,10)
def getSegment(curIndex,getSize):
abc = [“a”,“b”,“c”,“d”,“e”,“f”,“g”,“h”,“i”,“j”,“k”,“l”,“m”,“n”,“o”,“p”,“q”,“r”,“s”,“t”,“u”,“v”,“w”,“x”,“y”,“z”]
stratGet = (curIndex - 1) * getSize
getData = abc [stratGet :curIndex * getSize ]
totalIndexTuple = divmod(len(abc),getSize)
totalIndex = totalIndexTuple[0] +( 1 if totalIndexTuple[1] > 0 else 0)
return (getData,totalIndex)
result = getSegment(2,5)
print(result[0])
print(result[1])
evenNumber = []
i = 0
while i <= 100:
if i %2 == 0:
evenNumber.append(i)
i+=1
print(sum(evenNumber))
def avg(seq):
totalLen = 0
everySeq =[]
for i in seq:
Len = len(i)
everySeq.append(sum(i))
print(sum(i) / Len)
totalLen += Len
print(sum(everySeq) / totalLen)
avg([[10,12,13],[12,11,15],[2,5,4,2]])
class myCalc:
def init(self,a,b):
self.a=a
self.b=b
def addition(self,Retain):
return round(self.a + self.b ,Retain)
def subtraction(self,Retain):
return round(self.a - self.b,Retain)
def multiplication(self,Retain):
return round(self.a * self.b,Retain)
def division(self,Retain):
return round(self.a / self.b,Retain)
while True:
get_num1 = input(“请输入第一个数字:”)
opera = input(“请输入运算符:”)
get_num2 = input(“请输入第二个数字:”)
get_retain = input(“请输入保留小数位数:”)
num1 = float(get_num1)
num2 = float(get_num2)
retain = int(get_retain)
result = 0.00
if opera == “+”:
result = myCalc(num1,num2).addition(retain)
elif opera == “-”:
result = myCalc(num1,num2).subtraction(retain)
elif opera == “*”:
result = myCalc(num1,num2).multiplication(retain)
else:
result = myCalc(num1,num2).division(retain)
print(“输出结果是:”,result)
def progress(val):
num= 1 + val
yearProgress=pow(num,365)
output =""
if yearProgress == num :
output =“原地踏步”
else:
output = str(round(yearProgress,1))
print(“一年进步值:”,output+“倍”)
#接受用户输入,然后调用progress函数
dayVal = input(“每天进步值:”)
progress(float(dayVal))
import random
seq=[]
i=0
while i<10:
seq.append(random.randint(1,100))
i += 1
getMin = min(seq)
print(“原列表值:”,seq)
print(“列表最小值:”,getMin)
def searchMax(item):
pro1 = {“product”:“iphone xs”,“screen”:5.8,“price”:8699,“weight”:“177克”,“depth”:7.7}
pro2 = {“product”:“iphone xs MAX”,“screen”:6.5,“price”:10699,“weight”:“208克”,“depth”:7.7}
pro3 = {“product”:“iphone xr”,“screen”:6.1,“price”:6499,“weight”:“194克”,“depth”:8.3}
proList = [pro1,pro2,pro3]
a=max(proList, key=lambda x: x[item])
msg ={“product”:“产品”,“screen”:“屏幕尺寸”,“price”:“起价”,“weight”:“重量”,“depth”:“厚度”}
print(“您获取的参数值信息是:”,msg[item])
return a
#通过接收用户输入的参数名,来获取相关产品
itemName = input(“请输入要查找配置最高的参数名称:”)
productItem = searchMax(itemName)
print(productItem)
num = 69 #定义一个整数值
print(“十进制转换二进制:”,"{:b}".format(num))
print(“十进制转换八进制:”,"{?}".format(num))
print(“十进制转换十六进制:”,"{:x}".format(num))
print(“十进制转换十六进制(0x格式):”,"{:#x}".format(num))
name = input(“输入字符:”)
print(name+“的ASCII码为:”,ord(name))
name = (“好好”,“常常”,“慢慢”,“略略”,“哈哈”,“很好”)
myslice =slice(0,6,2)
print(name[myslice])
name = [“好好”,“常常”,“慢慢”,“略略”,“哈哈”,“很好”]
print(“列表中有”,len(name),“人名”)
print(“长度为”,len(name))
help(“os”)
name = [“好好”,“常常”,“慢慢”,“略略”,“哈哈”,“很好”]
help(name) #查看列表name的帮助信息
dataType = {“int”:“整型”,“str”:“字符串类型”,“list”:“列表类型”,“tuple”:“元组类型”}
def Isinstance(i):
for j in dataType.keys():
if isinstance(i,eval(j)) == True:
print(“参数类型为:”,dataType[j])
Isinstance(10)
Isinstance([1,2,3])
Isinstance(“ABC”)
Isinstance((“A”,“B”))
#实现可以回调的的转换操作