标签:决定 指定 obb 因子 utf-8 锁定 case lin err
import itertools
a = ('1','2','3','4')
for i in range(1,5):
for k in itertools.permutations(a,i):
if 3 == len(k):
print(''.join(k))
for i in range(1,5):
for j in range(1,5):
for k in range(1,5):
if(i != k) and (i != j) and (j != k):
print(i,j,k)
b = [1000000,600000,400000,200000,100000,0]
r = [0.01,0.015,0.03,0.05,0.075,0.1]
cou = 0
you = int(input("你的业绩:"))
for i in range(len(b)):
if you > b[i]:
cou += (you - b[i]) * r[i]
print('提成额度',you-b[i],'提成点',str(r[i]*100)+'%','奖金:',(you - b[i]) * r[i])
you = b[i]
print(cou)
# 设这个数是 n,
# n+100 = a^2,
# a^2+168=b^2,
# 所以 (b+a)(b-a)=168=84*2 = 42*4 = 28*6 = 14*12,
# 由 b+a=84,b-a=2 解得 a=(84-2)/2=41,所以 n=41^2-100 = 1581,
# 由 b+a=42,b-a=4 解得 a=(42-4)/2=19,所以 n=19^2-100=261,
# 由 b+a=28,b-a=6 解得 a=(28-6)/2=11,所以 n=11^2-100 = 21 ,
# 由 b+a=14,b-a=12 解得 a=(14-12)/2=1,所以 n=1^2-100 = -99
for i in range(1, 85):
if 168 % i == 0:
j = 168 / i
x = 168 / j
a = (j-x)/2
n = a*a-100
if n - int(n) == 0:
print(int(n))
date = input("请输入日期<例 2019-10-08>:")
days = (0,31,59,90,120,151,181,212,243,273,304,334)
sum = 0
leap = 0
try:
y,m,d = date.split('-')
if 0 < int(m) <= 12:
sum = days[int(m)-1]
sum += int(d)
if (int(y) % 400 == 0) or ((int(y) % 4 == 0) and (int(y) % 100 != 0)):
leap = 1
if (leap == 1) and (int(m) > 2):
sum += 1
print(sum)
else:
print("月份输入错误")
except Exception as a:
print("请按照提示输入")
li = []
for i in ("x","y","z"):
inp = input("输入 %s 数字:" %i)
li.append(int(inp))
li.sort()
print(li)
for i in range(10):
for j in range(1,i+1):
print("%d*%d=%d"%(j,i,i*j),end=' ')
print()
import time,datetime
print(datetime.datetime.now())
time.sleep(1)
print(datetime.datetime.now())
time.sleep(1)
print(time.localtime())
time.sleep(1)
print(time.strftime('%Y-%m-%d %H:%M:%S',time.gmtime()))
a = 0 #1,1 2 3 5 8 13 21 34
b = 1 #1 2 3 5 8 13 21 34 55
for i in range(1, 13):
print('%s月:有%s只兔子' % (i, b))
a, b = b, a + b
cou = 0
for i in range(101, 201):
k = 0
for j in range(2, i):
if i % j == 0:
k += 1
#print(i, j, end=' ')
if k == 0:
cou += 1
print(i)
print("总共" + str(cou) + "个素数")
import requests
for i in ur:
try:
url = 'http://'+i
r = requests.get(url)
if r.status_code == 200:
print(url)
except Exception as err:
print()
for x in range(100,1000):
a = str(x)
if int(a[0])**3+int(a[1])**3+int(a[2])**3 == x:
print(x)
90=2*3*3*5
while True:
x = int(input("输入整数:"))
print('%d='%x,end='')
while x > 1:
for i in range(2,x+1):
if x % i == 0:
x = int(x/i)
if x == 1:
print('%d' % i, end='')
else:
print('%d*' % i,end='')
print()
def sum(count):
number = 0
string = 0
space = 0
other = 0
for i in count:
if i.isdigit():
number += 1
elif i.isalpha():
string += 1
elif i.isspace():
space += 1
else:
other +=1
return '数字:'+str(number) + ';字母:'+ str(string) + ';空格:'+ str(space) +';其他:' + str(other)
print(sum('my name is fana 1234567'))
xx = input("输入:")
print(sum(xx))
number = int(input("请输入数字:"))
frequency = int(input("次数:"))
x = number
a = []
sum = 0
for i in range(frequency):
a.append(x)
c = str(x)+str(number)
x = c
for j in range(len(a)):
sum += int(a[j])
for k in a:
if k == a[-1]:
print(k,end='')
else:
print(str(k),end='+')
print('=%d' % sum,end='')
ball = 100
hop = []
for i in range(10):
if i == 0:
hop.append(ball)
else:
hop.append(ball*2)
ball = ball / 2
print("第%s次,反弹%s米" % (i+1, ball))
print("第10次落地,共经历%s米"%(sum(hop)))
x = 1
for i in range(9,0,-1):
print(i,end=' = ')
x = (x+1)*2
print(x)
from sys import stdout
for j in range(2, 1001):
k = []
n = -1
s = j
for i in range(1, j):
if j % i == 0:
n += 1
s -= i
k.append(i)
if s == 0:
print(j)
for i in range(n):
stdout.write(str(k[i]))
stdout.write(' ')
print(k[n])
for i in itertools.permutations(red):
for j in zip(i, blue):
if j in [('a','x'),('c','x'),('c','z')]:
break
else:
for k in range(len(red)):
print(i[k], blue[k])
#2 ==========================
for player1 in 'cab':
for player2 in 'xyz':
if player1 == 'c' and player2 != 'x' and player2 != 'z':
remain2 = set('xyz') - set(player2)
print("{}----{}".format(player1,player2))
if player1 == 'a' and player2 != 'x' and player2 in remain2:
remain2 -= set(player2)
print("{}----{}".format(player1,player2))
if player1 == 'b' and player2 in remain2:
print("{}----{}".format(player1,player2))
*
***
*****
*******
*****
***
*
#==1============
a = "*"
c = 1
b = 4
for i in range(b):
c += 2
for i in range(b):
print(a.center(c,' '))
a = a + "**"
for j in range(b):
if j == 0:
a = a[:-2]
continue
else:
a = a[:-2]
print(a.center((c),' '))
#==2============
from sys import stdout
for i in range(4):
for j in range(2 - i + 1):
stdout.write(' ')
for k in range(2 * i + 1):
stdout.write('*')
print()
for i in range(3):
for j in range(i + 1):
stdout.write(' ')
for k in range(4 - 2 * i + 1):
stdout.write('*')
print()
a = 2
b = 1
count = 0
for i in range(20):
count += a/b
b, a = a, a+b
print("%s = %s" %(i,count))
# c = 0
# for i in range(1,21):
# c = c+i
# print("%s = %s + %s"%(c,c-i,i))
# ==== 后面有! 是阶乘 ====
c = 1
x = 0
for i in range(1,21):
c = c * i
x = x +c
#print("%s! = %s" %(i,c))
if i == 20:
print("%s" % (i), end='')
else:
print("%s+" %(i),end='')
print("=%s"%x,end='')
def sum(n):
if n == 0:
con = 1
else:
con = n * sum(n - 1)
return con
print(sum(5))
def fan(inp):
if len(inp) == 1:
print(inp[-1])
else:
print(inp[-1])
fan(inp[:-1])
a = input("请输入:")
fan(a)
def age(x):
if x == 1:
one = 10
else:
one = age(x-1) + 2
return one
print(age(5))
x = input("请输入一个数:")
if not x.isdigit():
print("不是数字")
else:
n = str(x)
print('length:', len(n))
print('numbers: ',end='')
for i in range(len(n)-1, -1, -1):
print(n[i],end=' ')
x = input("请输入一个数:")
t = True
if x.isdigit():
n = str(x)
for i in range(len(n)):
print(n[i],n[-i-1])
if n[i] != n[-i-1]:
t = False
break
else:
print("请输入数字")
if t:
print("%s = %s 是回文数" %(x,t))
else:
print("%s = %s 不是回文数" %(x,t))
## 2 ###################
if len(n) == 5:
if n == "".join(reversed(n)):
print('{0}是回文数'.format(n))
else:
print('{0}不是回文数'.format(n))
else:
print("输入错误")
显示方式 | 效果 | 字体色 | 背景色 | 颜色 |
---|---|---|---|---|
0 | 默认 | 30 | 40 | 黑色 |
1 | 高亮 | 31 | 41 | 红色 |
4 | 下划线 | 32 | 42 | 绿色 |
5 | 闪烁 | 33 | 43 | 黃色 |
7 | 反显 | 34 | 44 | 蓝色 |
8 | 不可见 | 35 | 45 | 紫红色 |
22 | 非粗体 | 36 | 46 | 青蓝色 |
24 | 非下划线 | 37 | 47 | 白色 |
25 | 非闪烁 | |||
27 | 非反显 |
# 常见开头格式:
# \033[0m 默认字体正常显示,不高亮
# \033[32;0m 红色字体正常显示
# \033[1;32;40m 显示方式: 高亮 字体前景色:绿色 背景色:黑色
# \033[0;31;46m 显示方式: 正常 字体前景色:红色 背景色:青色
# \033[1;31m 显示方式: 高亮 字体前景色:红色 背景色:无
print('\033[31m 字体红色,但无背景色 \033[0m') # #红色
print('\033[1;45m 字体不变色,有背景色 \033[0m') # 有高亮
print('\033[1;35;46m 字体有色,且有背景色 \033[0m') # 有高亮
print('\033[1;31;44m'+'*' * 45)
print(' 错误次数超限,用户已被永久锁定,请联系管理员!') #字体颜色红色反白处理
print('*' * 45 + "\033[1;31;44m")
a = [1,2,3,4,5,6]
for i in a:
if i == a[len(a)-1]:
print(i,end='')
else:
print(i,end=',')
## === 2 ===
str = ','.join(str(i) for i in a)
print(str)
a = [1,2,3,4,5,6]
a.reverse()
print(a)
## --- 2 ----
for i in range(len(a)-1,-1,-1):
print(a[i])
week = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday']
a = []
inp = input("week:").upper()
for i in week:
if inp == i[0]:
a.append(i)
if len(a) >= 2:
inp1 = input("输入第二个字母:")
for j in a:
if inp1 == j[1]:
print(j)
else:
print(''.join(a))
## 求100之内的素数
cou = 0
for i in range(1,101):
k = 0
for j in range(2,i):
if i % j == 0:
k += 1
if k == 0:
cou += i
print(i,end=',')
print("总和是%s" %cou)
li = [12,3,5,6,89,23,7,34,21,100]
for i in range(1,len(li)):
for j in range(len(li)-i):
if li[j] < li[j+1]:
temp = li[j]
li[j] = li[j+1]
li[j+1] = temp
print(li)
## == 2===
for i in range(9):
for j in range(i+1, 10):
if li[j-1] > li[j]:
a = li[j]
li[j] = li[j-1]
li[j-1] = a
print(li)
li = [3, 5, 6, 7, 12, 21, 23, 34, 89, 100]
number = int(input("请输入数字:"))
li2 = li
li2.append(number)
for i in range(len(li2)):
for j in range(i+1, len(li2)):
if li2[j-1] > li2[j]:
a = li2[j]
li2[j] = li2[j-1]
li2[j-1] = a
print(li2)
li = [3, 5, 6, 7, 12, 21, 23, 34, 89, 90,100]
li.reverse()
print(li)
## === 2 ===
li2 = []
for i in range(len(li)-1,-1,-1):
li2.append(li[i])
print(li2)
## === 3 ===
for i in range(int(len(li)/2)):
li[i] = li[len(li) - i - 1]
li[len(li) - i - 1] = li[i]
print(li)
b = [[3, 5, 6], [7, 12, 21], [23, 34, 89]]
for i in range(3):
print(b[i][i])
sum1 = sum1 + b[i][i]
print(sum1)
for i in range(1,101):
coun += i
print(coun)
X = [[12,7,3],
[4 ,5,6],
[7 ,8,9]]
Y = [[5,8,1],
[6,7,3],
[4,5,9]]
n = [[],[],[]]
for i in range(len(X)):
for j in range(len(Y)):
print("%s+%s=%s" %(X[i][j],Y[i][j],X[i][j]+Y[i][j]))
n[i].append(X[i][j]+Y[i][j])
print(n)
username = input('请输入你要注册的用户名:')
password = input('请输入你要注册的密码:')
with open('list_of_info',mode='w',encoding='utf-8') as f:
f.write('{}\n{}'.format(username,password))
print('恭喜您,注册成功')
lis = []
i = 0
while i < 3:
usn = input('请输入你的用户名:')
pwd = input('请输入你的密码:')
with open('list_of_info',mode='r+',encoding='utf-8') as f1:
for line in f1:
lis.append(line)
if usn == lis[0].strip() and pwd == lis[1].strip():
print('登录成功')
break
else:print('账号和密码错误')
i+=1
with open('fan','r',encoding='utf-8') as f,open('fan.bak','w',encoding='utf-8') as f2:
for line in f:
if '黄曼' in line:
line = line.replace('黄曼','香儿') #把黄曼替换成香儿
f2.write(line)
import os
os.remove('fan')
os.replace('fan.bak','fan')
list3 = [
{"name": "alex", "hobby": "抽烟"},
{"name": "alex", "hobby": "喝酒"},
{"name": "alex", "hobby": "烫头"},
{"name": "alex", "hobby": "Massage"},
{"name": "wusir", "hobby": "喊麦"},
{"name": "wusir", "hobby": "街舞"},
]
# 如何把上面的列表转换成下方的列表?
list4 = [
{"name": "alex", "hobby_list": ["抽烟", "喝酒", "烫头", "Massage"]},
{"name": "wusir", "hobby_list": ["喊麦", "街舞"]},
]
#####==============#####
list4 = [{'name':None,'hobby':[]},{'name':None,'hobby':[]}]
for i in list3:
for k,v in i.items():
if v == 'alex':
list4[0]['name'] = v
list4[0]['hobby'].append(i['hobby'])
if v == 'wusir':
list4[1]['name'] = v
list4[1]['hobby'].append(i['hobby'])
print(list4)
import random
####1.只有数字=========================
code = ""
for i in range(6):
add_num = random.randrange(10)
code+=str(add_num)
print(code)
####2.只有字母=======================
import string
#s = string.ascii_lowercase # 所有小写字母(a-z)
s=string.ascii_letters #所有大小写字母(a-z,A-Z)
# s=string.ascii_uppercase #所有大写字母(A-Z)
a = ''
for i in range(6):
r = random.choice(s)
a += r
print(a)
####3.字母和数字混合的随机验证码==============
#大写字母 chr(random.randrange(65,91))
#小写字母 chr(random.randrange(97,123))
def v_code():
code1 = ""
for i in range(6):
add=random.choice([random.randrange(10),chr(random.randrange(65,91)),chr(random.randrange(97,123))])
code+=str(add)
print(code1)
v_code()
import time
def dateRange(year):
fmt = '%Y-%m-%d'
bgn = int(time.mktime(time.strptime(year+'-01-01',fmt)))
end = int(time.mktime(time.strptime(year+'-12-31',fmt)))
list_date = [time.strftime(fmt,time.localtime(i)) for i in range(bgn,end+1,3600*24)]
return [i.replace('-','') for i in list_date]
print(dateRange('1991'))
T = True
while T:
inp = input("请输入:")
if inp.isdigit():
c = int(inp) * int(inp)
if c > 50:
print(c)
T = True
else:
print(c)
T = False
else:
print("请输入数字")
def exchange(a,b):
a,b = b,a
return a,b
a = 12
b = 23
print(exchange(a,b))
def compare(i,j):
if i > j:
print('{} 大于 {}'.format(i, j))
elif i < j:
print('{} 小于 {}'.format(i, j))
elif i == j:
print('{} 小于 {}'.format(i, j))
else:
print('输入错误')
sumber = input('请输入2个数字用空格隔开:')
if ' ' in sumber:
try:
a, b = sumber.split(' ')
if a.isdigit() and b.isdigit():
compare(a,b)
else:
print("请输入数字")
except Exception as error:
print('输入有误')
else:
print('请用空格分开')
flag = False
def login(func):
def inner(*args,**kwargs):
global flag
if flag == True:
ret = func(*args,**kwargs)
return ret
else:
user = input('username:')
pawd = input("密码:")
if user == 'fana' and pawd == '123456':
flag = True
ret = func(*args,**kwargs)
return ret
else:
print('登陆失败')
return inner
@login
def shoplist_add():
print("购买一件商品")
@login
def shoplist_del():
print("别要了")
shoplist_add()
shoplist_add()
shoplist_del()
shoplist_add()
shoplist_del()
def func_log(fun):
def inner(*args,**kwargs):
ret = fun(*args,**kwargs)
with open("file.txt",'a+',encoding='UTF-8') as f1:
f1.write(fun.__name__+'\n')
return ret
return inner
@func_log
def func():
print('func')
@func_log
def fana():
print('fana')
然后为刚刚的函数编写装饰器,实现下载的网页存放在文件中,如果文件内有值(文件大于0)就优先从文件读取,否则就去下载
import requests,os
def cache(func):
def inner(*args,**kwargs):
a = args[0][11:-4]
ret = func(*args,**kwargs)
if not os.path.exists(a): #没有这个文件就写
with open(a,'w',encoding='utf-8') as f:
f.write(ret)
return ret
elif os.path.getsize(a): #文件大于0 就读文件
with open(a,'r',encoding='utf-8') as f:
return f.readlines()
else: #如果有文件,但是0k 就重新写
with open(a,'w',encoding='utf-8') as f:
f.write(ret)
return ret
return inner
@cache
def user_url(url):
res = requests.get(url)
res.encoding = 'utf-8'
return res.text
print(user_url('http://www.baidu.com'))
print(user_url('http://www.qq.com'))
def check_file(filename,aim):
with open(filename,encoding='utf-8') as f: #句柄 : handler,文件操作符,文件句柄
for i in f:
if aim in i:
yield i
g = check_file('fana','生成器')
for i in g:
print(i.strip())
def check_file(filename):
with open(filename,encoding='utf-8') as f: #句柄 : handler,文件操作符,文件句柄
for i in f:
yield '***'+i
for i in check_file('fana'):
print(i.strip())
标签:决定 指定 obb 因子 utf-8 锁定 case lin err
原文地址:https://www.cnblogs.com/fan-gx/p/11637355.html