import random
沿河ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:18982081108(备注:SSL证书合作)期待与您的合作!
max_n = 100
i = 0
while True:
i += 1
# 随机运算,0+,1-
op = random.randint(0, 1)
# +
if op == 0:
x1 = random.randint(0, max_n)
x2 = random.randint(0, max_n - x1)
result = x1 + x2
qst = str(x1) + "+" + str(x2) + "="
question = [qst, result]
# -
elif op == 1:
x1 = random.randint(0, max_n)
x2 = random.randint(0, x1)
result = x1 - x2
qst = str(x1) + "-" + str(x2) + "="
question = [qst, result]
x = input("第{:2d}题:{}".format(i + 1, question[0]))
if int(x) == int(question[1]):
print("回答正确!")
else:
print("回答错误!{}{}".format(question[0], question[1]))
是利用原来的向下取整的机制如果原来是
实际上Python的round()函数可以接受两个参数round(value,ndigits),第一个参数为实际操作数,第二个参数为实际保留几位,如果第二个参数不填,则默认保留到整数位。
Python3.X对于浮点数默认的是提供17位数字的精度。
from datetime import datetime
import math
def last_xmonth(x):
now = datetime.now()
if x==0:
return now
else:
a = x%12 # 取余数 前a个月 限制0a12
b = math.ceil(x/12)+1 if x%12==0 else math.ceil(x/12) # 前b-1年
if xnow.month:
date1 = datetime.strftime(datetime(now.year-b+1,now.month-a,now.day),'%Y-%m-%d')
else :
date1 = datetime.strftime(datetime(now.year-b,now.month+12-a,now.day),'%Y-%m-%d')
return date1