import random #求随机能被3和5同时整除的数 num=random.randint(1,1000) if num % 3==0 and num % 5 ==0: print(f'数字{num}可以被3和5整除') elif num % 3 ==0: print(f'数字{num}可以被3整除') elif num % 5 ==0: print(f'数字{num}可以被5整除') else: print(f'数字{num}不可以被3整除也不可以被5整除')
season=random.choice(['春','夏','秋','冬']) if season=='春': print('春天到了,万物复苏的季节,春意盎然') elif season=='夏': print('夏天到了,烈日炎炎,准备避暑') elif season=='秋': print('秋天到了,丰收的季节,硕果累累') elif season=='冬': print('冬天到了,准备冬藏,太冷了')
#求随机直径圆的周长和面积 radius=random.randint(1,10) length=2*3.14*radius area=3.14*radius**2 print(f'直径为{radius:.2f} 的圆周长是:{length:.2f},面积是{area:.2f}')
height=round(random.uniform(1.5,2),1) weight=random.randint(35,70) res=weight / (height**2) if 18.5<=res<=24.9: print(f'身高为{height}米,体重为{weight}公斤的你,属于正常健康身体!') elif res<18.5: print(f'身高为{height}米,体重为{weight}公斤的你,偏瘦需要补充营养!') elif res>24.9: print(f'身高为{height}米,体重为{weight}公斤的你,肥胖的你,赶紧去健身!')
标签:elif,Python,season,代码,random,num,print,整除 From: https://www.cnblogs.com/ygyalex/p/17035236.html