#数硬币作业
ls = [10,8,5,3,27,99]
x = 0
for i in ls:
if i%2 == 0:
x += i//2
else:
x +=i//2+1
peint()
#获取100以内的素数,村存储到列表中
b = []
for i in range(2, 100):
for a in range(2, i-1):
if i % a == 0:
break
else:
b.append(i)
#从素数列表中,通过if判断,打印出孪生素数
for x in range(2,len(b)):
if b[x] - b[x-1] ==2:
print(b[x-1],b[x])
ls = [1,2,3,4,54,566,723,4,2145,56,2344,5]
ls.sort()
print(ls)
ls.reverse()
print()
#列表合并排序
lsa = [1,2,3,4,54]
lsb = [50,20,45,85]
lsa.extend(lsb)
lsa.sort()
print(lsa)
ls = [1,2,3,4,5,6,7,8]
print("列表",ls)
num_max = ls[0]
num_min = ls[0]
num_and = 0
for i in range(1,len(ls)):
if num_max < ls[i]:
num_max = ls[i]
elif num_min > ls[i]:
num_min = ls[i]
else:
pass
print("最大值:",num_max)
print("最小值:",num_min)
for i in ls:
num_and += i
print("和:",num_and)
num_average = num_and/len(ls)
print("平均值:",num_average)
#根据是否存在交集来判断列表是否在另一个列表中,若存在交集,则自然证明存在
a = [1,2,3,6,8,9,10,11,12]
b = [1,2,3]
j = list(set(a).intersection(set(b)))
print(j)
unm=int(input("请输入一个大于9的数(10~100):"))
while unm == 10 :
print("能被9整除")
break
if 100>=unm>10:
y=int(unm/10%10)
z=int(unm%10)
h=y+z
print(h)
if (unm -h) %9==0:
print("能被9整除")
import random
lt=[2,3,4,5,6]
x=random.randint(0,10)
lt.append(x)#末尾开始
print(lt)
lt.insert(2,x)#从3开始
print(lt)
'''
ls富
2021/1/16
users = []
while True:
print("欢迎登录我们的用户管理系统")
print("\t\t 1、用户注册")
print("\t\t 2、用户登录")
print("\t\t 3、退出系统")
choice = input("请选择您的操作:")
if choice == "1":
while True:
print("欢迎进入到用户注册页面")
username = input("请输入用户名称:")
password = input("请输入用户密码:")
confirm_password = input("请再次确认密码:")
# 数据校验
# 用户名称不能为空
if username == None or len(username) == 0:
print("对不起,用户为空")
continue
# 用户名称不能重复
flag = False
for u in users:
if u.get("username") == username:
print("对不起,该用户已经存在,请重新注册")
flag = True
break
if flag:
continue
# 密码长度不能少于3位
if len(password) < 3:
print("对不起,密码长度不能少于3位")
continue
# 两次密码不一致
if password != confirm_password:
print("两次密码不一致")
continue
# 最后如何保存用户名称和密码
user = {"username": username, "password": password}
users.append(user)
print("用户注册成功,请登录")
break
elif choice == "2":
print("欢迎进入到用户登录页面")
username = input("请输入用户名称:")
password = input("请输入用户密码:")
# 判断用户名和密码是否存在于users
for user in users:
if user["username"] == username and user.get("password") == password:
print("恭喜您,{},登录成功".format(username))
else:
print("对不起,登录失败,请重新登录~~")
elif choice == "3":
sys.exit()
else:
print("输入有误,请重新选择")
lt=[1,3,5,3,4,100,-21,1,6]
for i in range(len(lt) - 1):
for j in range(len(lt) - 1 - i):
if lt[j] > lt[j + 1]:
lt[j], lt[j + 1] = lt[j + 1], lt[j]
print(lt)
num = int(input("请输入你要计算的十以内的数字"))
n = int(input("请输入你要计算的次数")) #即重叠数 每一次叠一个:2 22 222
l = 0
s = 0
z = 0
while l < n:
s += num*(10**l) #每一次数的和 2 + 20 + 200 +2000...l:即可理解为几位
l += 1
print(s)
z += s #再把每一个s 相加
print(z)
#(输入) 请输入你要计算的十以内的数字2
请输入你要计算的次数4
#(输出)
2
22
222
2222
2468
list1 = [1,2,3,4,5,6,7]
list2 = [8,9,10,11,12,13]
result = []
while list1 and list2:
if list1[0] < list2[0]:
result.append(list1[0])
list1.remove(list1[0])
else:
result.append(list2[0])
list2.remove(list2[0])
for i in list2:
result.append(i)
result.sort()
print(result)