count = 1
while count < 11:
if count == 6:
count += 1
continue
print(count,end=' ')
count += 1
#2. 求1-100的所有数的和
for i in range(101):
if i % 2 == 1:
print(i,end=' ')
#3. 输出 1-100 内的所有奇数
for i in range(101):
if i % 2 == 1:
print(i,end=' ')
#4. 输出 1-100 内的所有偶数
i=0
while i <= 100:
i += 1
if i % 2 == 0:
print(i,end=' ')
#5. 求1-2+3-4+5 ... 99的所有数的和
i = 0
sum = 0
while i < 100:
i += 1
if i % 2 == 1:
sum += i
else:
sum = sum - i
print(sum)
#6. 用户登陆(三次机会重试)
def login():
i = 1
while True:
name = input("请输入用户名:")
if name != "hanyi":
print('"用户名错误,请重新输入"')
if i>=3:
print('"三次用户名输入错误"')
break
else:
i+=1
else:
print("用户名输入正确!")
j=1
while True:
psw = input("请输入密码:")
if psw != '123456':
print('"密码错误,重新输入"')
if j >= 3:
print('"三次密码输入有误"')
break
else:
j += 1
else:
print('"登录成功"')
break
break
login()
#7:猜年龄游戏 要求: 允许用户最多尝试3次,3次都没猜对的话,就直接退出,如果猜对了,打印恭喜信息并退出
guess_age = 12
num = 0
while num < 3:
age = input("请输入你猜测的年龄:")
if int(guess_age) > int(age):
print("你才小了!")
elif int(guess_age) < int(age):
print("你猜大了!")
else:
print("恭喜你,你猜对了!")
num += 1
else:
print("游戏结束")
#8:猜年龄游戏升级版(选做) 要求: 允许用户最多尝试3次 每尝试3次后,如果还没猜对,就问用户是否还想继续玩,如果回答Y或y, 就继续让其猜3次,以此往复,如果回答N或n,就退出程序 如何猜对了,就直接退出
guess_age = 12
num = 0
while num < 3:
age = input("请输入你猜测的年龄:")
if int(guess_age) > int(age):
print("你才小了!")
elif int(guess_age) < int(age):
print("你猜大了!")
else:
print("恭喜你,你猜对了!")
break
if num == 2:
t =input("请问是否仅需游戏,继续游戏请输入Y或y,退出请输入N或n:")
for t in ['Y','y']:
num = -1
for t in ['N','n']:
break
num += 1
#9.for循环打印99乘法表
for i in range(1,10): for j in range(1,10): print(f'{i}x{j}={i*j:^3}',end='') if i == j: print(" ") break
#10.for循环打印金字塔:如下
def pyramid(n): for i in range(1,n): print(' '*(n-(i-1))+'*'*(2*i-1)) pyramid(6)