# 条件判断 # 1 print("#1") age = 20 if age >= 18: print(‘your age is‘, age) print(‘adult‘) print("---------------------") # 2 print("#2") age = 3 if age >= 18: print(‘your age is‘, age) print(‘adult‘) else: print(‘your age is‘, age) print(‘teenager‘) print("---------------------") # 3 print("#3") age = 3 if age >= 18: print(‘adult‘) elif age >= 6: print(‘teenager‘) else: print(‘kid‘) print("---------------------") # 4 print("#4") s = input(‘birth: ‘) # input返回的数据类型是str,不能直接和整数比较,用int()强转 # 当然如果输入类似‘abc‘这种非数字时,需要捕获程序运行期的错误,这里不展开讨论 birth = int(s) if birth < 2000: print(‘00前‘) else: print(‘00后‘) print("---------------------")
时间: 2024-10-24 23:33:12