python基础语法2
2021-06-08 03:02
标签:结果 优秀 art 内容 put 语法 使用 str 多分支 输入:input() 目的:为了让计算机像人一样接收外界输入的内容。 输出:print() 目的:为了让计算机像人一样把自己处理的结果输出给用户。 完整语法: if 条件1: 代码1 代码2 ... elif 条件2: 代码1 代码2 ... elif 条件3: 代码1 代码2 ... else: 代码1 代码2 ... 1.单分支 1.基本使用 2.死循环 3.结束循环的两种方式 4.while加continue,结束本次循环 5.while加else else里面的内容,必须要循环正常结束才能运行,被break结束的循环是不能运行else的。 python基础语法2 标签:结果 优秀 art 内容 put 语法 使用 str 多分支 原文地址:https://www.cnblogs.com/yuxinplus/p/14543663.htmlpython基础语法
1.与用户交互
2.流程控制之if判断
# print(‘start...‘)# inp_name = input("请输入您的用户名:")# if inp_name == "egon":# print(‘ok‘)# print(‘end...‘)# print(‘start...‘)# inp_name = input("请输入您的用户名:")# if inp_name == "egon":# print(‘ok‘)# else:# print(‘error‘)# print(‘end...‘)# 如果:成绩>=90,那么:优秀# 如果成绩>=80且# 如果成绩>=70且# 其他情况:很差# score = input("your score: ")# score = int(score)# if score >= 90:# print("优秀")# if 10 > 3:# print(‘ok‘)# elif score >= 80 and score # print("良好")# elif score >= 70 and score # print("普通")# else:# print(‘很差‘)# 优化版# score = input("your score: ")# score = int(score)# if score >= 90:# print("优秀")# elif score >= 80:# print("良好")# elif score >= 70:# print("普通")# else:# print(‘很差‘)3.流程控制之while循环
# i=0# while i # print(i) # 4# i += 1 # i=5"""01234"""# while True:# # print(‘1111‘)# 1+1# 1、break:直接终止本层循环,不会有下一次循环# tag = True# while tag:# print(‘start...‘)# break# print(‘end...‘)# 2、条件改为假:不会直接终止本层循环,会在下一次循环时终止# tag = True# while tag:# print(‘start...‘)# tag = False# print(‘end...‘)# i = 0# while i # if i == 3:# i+=1# continue# print(i) ## i+=1 # i=3