#1. 使用while循环输出1 2 3 4 5 6 8 9 10 #2. 求1-100的所有数的和 #3. 输出 1-100 内的所有奇数 #4. 输出 1-100 内的所有偶数 #5. 求1-2+3-4+5 ... 99的所有数的和 #6. 用户登陆(三次机会重试) #7:猜年龄游戏 要求: 允许用户最多尝试3次,3次都没猜对的话,就直接退出,如果猜对了,打印恭喜信息并退出 #8:猜年龄游戏升级版 要求: 允许用户最多尝试3次 每尝试3次后,如果还没猜对,就问用户是否还想继续玩,如果回答Y或y, 就继续让其猜3次,以此往复,如果回答N或n,就退出程序 如何猜对了,就直接退出
1
# count = 0 # while count < 10: # count+=1 # if count == 8: # continue # else: # print(count)
2
# count=1 # s=0 # while count<101: # s=s+count # count+=1 # else: # print(s)
3
# for count in range(1,101,2): # print(count) # 或者用while # count=1 # while count<100: # print(count) # count=count+2
5
# count=1 # s1=0 # s2=0 # while True: # s1=count+s1 # if count==99: # print(s1-s2) # break # count+=1 # s2=count+s2 # count+=1
6
# count = 1 # while count<4: # name=input('请输入您的名字: ') # pwd=input('请输入您的密码: ') # if name=='huihui' and pwd=='123': # print('登录成功!') # else: # print('登录失败!') # count+=1
7
# tag = True # count = 0 # while tag: # age = input('请输入年龄: ') # if age == '25': # print('恭喜答对!') # tag=False # else: # print('答错') # count += 1 # if count % 3 == 0: # print('是否继续玩?Y or N') # choice = input('请输入您的选择: ') # if choice == 'N': # tag = False
8打印九九乘法表
for i in range(1,10): for j in range(1,i+1): print('%s*%s=%s' %(i,j,i*j),end=' ') print()
9打印金字塔
for i in range(6): for k in range(5-i): print(" ",end=" ") for j in range(2*i+1): print("*", end=" ") print()