'''b.实现用户输入用户名和密码,当用户名为 seven且密码为123时,显示登陆成功,否则登陆失败,
失败时允许重复输入三次'''
i=0
while i<4:
uaername=input("请输入您的用户名!")
pswd=input("请输入您的密码!")
if uaername=="seven" and pswd=="123":
print("等离成功!")
break
else:
print("等离失败,请重新输入!")
i+=1
else:
print("三次输入失败后,不再允许登录!!!")
'''c.实现用户输入用户名和密码,当用户名为 seven或alex且 密码为123时
,显示登陆成功,否则登陆失败,失败时允许重复输入三次'''
i=0
while i<4:
uaername=input("请输入您的用户名!")
pswd=input("请输入您的密码!")
if (uaername=="seven" or uaername=="alex") and pswd=="123":
print("等离成功!")
break
else:
print("等离失败,请重新输入!")
i+=1
else:
print("三次输入失败后,不再允许登录!!!")
# 1)使用while循环实现输出2-3+4-5+6.....+100的和
i=2
sum=2
while i<100:
i+=1
if i%2:#为奇数
sum-=i
print(i,sum)
else:
sum += i
print(i, sum)
# 输出一百以内的所有奇数
for i in range(1,100,2):
print(i)
# >>> name = " aleX "
# >>> name.strip()
# 'aleX'
# >>> name.startswith("al")
# False
# >>> name.endswith("X")
# False
# >>> name.replace("l","p")
# ' apeX '
# >>> name.split('l')
# [' a', 'eX ']
# >>> type(name.split('l'))
# <class 'list'>
# >>> name.upper()
# ' ALEX '
# >>> name.lower()
# ' alex '
# >>> name[1]
# 'a'
# >>> name[:2]
# ' a'
# >>> name[-2:]
# 'X '
# >>> name.index("e")
name="alex"
for i in name:
print(i)#a l e x
# h.请删除列表中的第2至4个元素,并输出删除元素后的列表
li=[1,2,3,4]
print(li[1:3])#23
print(li[::-1])#4321
tu=("alex",[11,22,{"k1":'v1',"k2":["age","name"],"k3":(11,22,33)},44])
# print(type(tu(1)(2)))
# print(type(tu(1)(2).get('k2')))
# tu(1)(2).get('k2').append('seven')
tu[1][2].get('k2').append('s')
print(tu)
dic={'k1':"v1","k2":"v2","k3":[11,22,33]}
dic.get('k3').append(1)
print(dic)#{'k1': 'v1', 'k2': 'v2', 'k3': [11, 22, 33, 1]}
# 将列表li = ["alex", "seven"]转换成字典且字典的key按照10开始向后递增
li = ["alex", "seven"]
li_c={}
for k,v in enumerate(li,10):
li_c[k]=[v]
print(li_c)
# 1. 编制一个返回值为bool型的函数isPrimer(),用于判断参数是否为素数;
def isPrimer(num):
for i in range(2, num):
if num%i == 0:
return False
return True
num = int(input('请输入一个数字:'))
print(isPrimer(num))
import random
def get(start,end,count):
l=[random.randint(start,end+1)for i in range(count)]
# print(l,i)
return l
print(get(1,41,5)+get(1,41,5))#[35, 14, 19, 28, 15, 18, 26, 14, 13, 20]
print([1]+[2])#[1, 2]