# 单分支 # age=int(input("请输入你的年龄:")) # if age>=18: # print('符合成年标准') # else: # print('未成年') # pass # # # 多分支 # scross=int(input('请输入您需要判断的成绩:')) # if scross>=90: # print('成绩优秀') # pass # elif scross>=80: # print('成绩良好') # pass # elif scross>=70: # print('成绩中等') # pass # elif scross>=60: # print('成绩及格') # pass # else: # print('成绩不合格,请继续努力!') # 案例 # 石头剪刀布游戏 # import random # count=1 # while count<=3: # count += 1 # person=int(input('来吧!请出拳[0:石头; 1:剪刀;2:布]:')) # computer=random.randint(0,2) # if person>2 or person<0: # print("不好意思,你的出拳不符合规则") # if person==0 and computer==1: # print('不错,你赢了') # pass # elif person==1 and computer==2: # print('不错,你赢了') # pass # elif person==2 and computer==0: # print('不错,你赢了') # pass # else: # print('HHH你输了') # pass # 嵌套选择语句 多阶段或者多层次选择判断 # 申请奖学金资格判断 # xuefen=int(input('请输入你的学分:')) # if xuefen>=60: # chengji = int(input('请输入你的学业成绩:')) # # print('学业成绩:{}’.format(chengji)) # if chengji>=100: # print('恭喜你,达到申请资格') # pass # else: # print('你的学业成绩不符合申请资格') # pass # else: # print('你的表现不符合申请条件') # 循环 # 打印1~100数字 # a=1 # while a<=100: # print(a) # pass # a +=1 # while循环的嵌套 # 案例:九九乘法表 # row=9 # while row>=1: # col=1 # while col<=row: # print('%d*%d=%2d'%(col,row,col*row),end=' ') # col += 1 # #pass # print('') #换行作用,空字符 # row -= 1 # print(' ') # # pass # # 案例: 打印三角形 (等腰三角形) # row=1 # while row<=7: # k=1 # while k<=7-row: # print(' ',end='') #打印空格的位置 # k+=1 # col=1 # while col<=2*row-1: # print('.',end='') #打印三角形占位符 . # col+=1 # pass # print() # row+=1 # pass # break推出循环 continue跳过本次循环 # print("---------continue和break的使用-----------") # a='i live python' # for i in a: # if i=='p': # # continue # break # pass # print(i,end='') # # print('------------循环的嵌套-----------------') # zhanghao='2011200426' # pw='hyl950905' # for i in range(3): # c=input('请输入你的账号:') # p=input('请输入你的密码:') # print() # if c==zhanghao and p==pw: # break # pass # else: # print('登入异常,请五分钟后重新登入!') # # print('-------------根据BIM指数判断体重情况------------') # a=float(input('请输入你的身高/m:')) # print('身高:%fm' %(a)) # b=float(input('请输入你的体重/kg:')) # print('体重:%fkg' %(b)) # BIM=b/(a*a) # if BIM<18.5: # print('最终判断结果为:体重过轻') # pass # elif BIM<25: # print('最终判断结果为:体重正常') # pass # elif BIM < 28: # print('最终判断结果为:体重过重') # pass # elif BIM < 32: # print('最终判断结果为:体重肥胖') # pass # else: # print('最终判断结果为:体重严重肥胖') # print('------------猜年龄小游戏------------') # import random # c=1 # Y=1 # y=1 # N=0 # n=0 # for i in range(3): # ccage=int(input('请输入你猜测的年龄:')) # age=random.randint(0,150) # # print(age) # if ccage!=age: # print('猜测错误!' # '目前你有两个选择:1 输入Y或者y继续玩;' # '2 输入N或者n退出程序') # xz=int(input('请输入你的选择:')) # print('选择:%d'%xz) # if xz==1: # continue # pass # else: # break # pass # i+=1 # elif ccage==age: # break # pass # else: # print('猜测不准确!') # pass # (bug) print('------------猜年龄小游戏------------') time=0 while time<=3: age=int(input('请输入你猜测的年龄:')) if age==25: print('恭喜你猜对了') break pass elif age<25: print('很遗憾你猜小了') pass elif age>25: print('很遗憾,你猜大了') pass time+=1 if time==3: choose=input('继续玩请输入【Y/y】\n' '退出程序请输入【N/n】') if choose=='Y' or choose=='y': time=0 pass elif choose=='N' or choose=='n': break pass else: print('请输入正常选项!') choose = input('继续玩请输入【Y/y】\n' '退出程序请输入【N/n】') pass