惠州营销网站制作,品牌网站建设相关问题,黄南州wap网站建设公司,erp软件开发平台一、行
(1) 物理行#xff1a;程序员编写代码的行。
(2) 逻辑行#xff1a;python解释器需要执行的指令。
(3) 建议#xff1a; 一个逻辑行在一个物理行上。 如果一个物理行中使用多个逻辑行#xff0c;需要使用分号#xff1b;隔开。
(4) 换行#xff1a; 如果…一、行
(1) 物理行程序员编写代码的行。
(2) 逻辑行python解释器需要执行的指令。
(3) 建议 一个逻辑行在一个物理行上。 如果一个物理行中使用多个逻辑行需要使用分号隔开。
(4) 换行 如果逻辑行过长可以使用隐式换行或显式换行。 隐式换行所有括号的内容换行,称为隐式换行 括号包括: () [] {} 三种显式换行通过折行符 \ (反斜杠)换行必须放在一行的末尾目的是告诉解释器,下一行也是本行的语句。 # 4个物理行 4个逻辑行
a 1
b 2
c a b
print(c)
# 1个物理行 4个逻辑行(不建议)
a 1;b 2;c a b;print(c)
# 4个物理行 1个逻辑行
# -- 换行符
d 1\
2\
34\
56
# -- 括号
e (12
34
5
6) 二、选择语句 1、if else 语句 if 条件1: 语句块1 elif 条件2: 语句块2 else: 语句块3以上条件都不满足 elif 子句可以有0个或多个。
else 子句可以有0个或1个且只能放在if语句的最后。
各条件之间互斥 调试让程序中断逐语句执行审查执行过程中变量取值
步骤加断点开始调试逐语句执行F8
断点必须要有用的地方空行位置无法设置断点。
调试目的目标与现状是否一致
编程提升点1 练习2在终端中输入课程阶段数,显示课程名称效果输入 输出1 Python语言核心编程2 Python高级软件技术3 Web 全栈4 人工智能num int(input(请输入数字))
if num 1:print(Python语言核心编程)
elif num 2:print(Python高级软件技术)
elif num 3:print(Web 全栈)
elif num 4:print(人工智能)
else:print(输入错误)# 优化,不需要转换没有用到计算
num (input(请输入数字))
if num 1:print(想想Python语言核心编程)
elif num 2:print(Python高级软件技术)
elif num 3:print(Web 全栈)
elif num 4:print(人工智能)
else:print(输入错误)
编程提升点2 练习4根据心理年龄与实际年龄打印智商等级。智商IQ 心理年龄MA 除以 实际年龄CA 乘以 100天才140以上包含超常120-139之间包含聪慧110-119之间包含正常90-109之间包含迟钝80-89之间包含低能80以下sys_age int(input(请输入心理年龄))
real_age int(input(请输入实际年龄))
IQ sys_age / real_age * 100
# if IQ 140:
# print(天才)
# elif 120 IQ 139:
# print(超常)
# elif 110 IQ 109:
# print(聪慧)
# elif 90 IQ 109:
# print(正常)
# elif 80 IQ 89:
# print(迟钝)
# else:
# print(低能)# 优化
if IQ 140:print(天才)
elif 120 IQ:print(超常)
elif 110 IQ:print(聪慧)
elif 90 IQ:print(正常)
elif 80 IQ:print(迟钝)
else:print(低能)
2、循环语句
1.while循环 while True:循环体if 条件break while循环计数
三要素开始结束间隔开始while 结束间隔 编程能力提升练习1 让下列代码重复执行输入y继续(不输入y则退出)
number int(input(请输入数字))
if number 0:print(正数)
elif number 0:print(负数)
else:print(零)
while True:number input(请输入数字)if int(number) 0:print(正数)elif int(number) 0:print(负数)else:print(零)if number y:break# 正确解答
while True:number int(input(请输入数字))if number 0:print(正数)elif number 0:print(负数)else:print(零)if input(请输入y键继续) ! y:break编程能力提升练习2
count 0
while True:print(跑圈)count 1if count 5:break
# 等价于
while count 5:print(跑圈)count 1
编程能力提升练习3 练习5
程序产生1个,1到100之间的随机数。
让玩家重复猜测,直到猜对为止。
每次提示大了、小了、恭喜猜对了,总共猜了多少次。# import random
# num random.randint(1,100)
# print(num)
# input_num int(input(请输入猜数))
# max num
# while num ! input_num:
# if input_num num:
# print(猜大了)
# else:
# print(猜小了)
# input_num int(input(请输入猜数))
# print(您猜对了)# 升级
# import random
# num random.randint(1,100)
# print(num)
# input_num int(input(请输入猜数))
# max_value 100
# min_value 0
# while num ! input_num:
# if input_num num:
# max_value input_num
# print(输大了)
# print(输入区间为%d ~ %d % (min_value, max_value))
# else:
# min_value input_num
# print(输大了)
# print(输入区间为%d ~ %d % (min_value,max_value))
# input_num int(input(请输入猜数))
# print(恭喜猜对了)# 优化 import random
num random.randint(1,100)
temp 0
max_value 100
min_value 0
while True:input_num int(input(请输入猜数))temp 1if num input_num:print(恭喜猜对了,猜了str(temp)次)breakelif input_num num:max_value input_numprint(输大了)print(输入区间为%d ~ %d % (min_value, max_value))else:min_value input_numprint(输小了)print(输入区间为%d ~ %d % (min_value,max_value))
2、for循环1 for item in 容器循环体item就是容器的每一个元素
容器只能为字符串 编程练习 练习在终端中输入一个四位整数计算每位相加和。
例如录入1234打印1234结果
效果
请输入四位整数1234
结果是10# num input(请输入四位整数)
# result 0
# # result num % 10
# # result num // 10 % 10
# # result num // 100 % 10
# # result num // 1000
# # print(result)
sum 0
for item in input(请输入四位整数):sum int(item)
print(sum) 3、for循环2 for range() 一个范围的整数# 写法1range(开始结束间隔)# 注意不包含结束 for item in range(1,5,2): print(item)# 写法2range(开始结束)# 注意间隔默认为1不包含结束 for item in range(1,5): print(item)# 写法3range(结束) # 注意开始默认为0间隔默认为1不包含结束 for item in range(5): print(item) 作业能力提升1
如果条件太多还是使用第一种方案代码的可读性高
如果条件简单且不多使用第二种方案介绍内存空间
(1) 电梯设置规定如果承载⼈不超过10⼈且总重量不超过1000千克可以正常使⽤否则提示超载。步骤:终端中获取人数/总重量显示电梯正常运行电梯超载# person_num int(input(请输入承载人数))
# weight_sum int(input(请输入总重量))
# if person_num 10 and weight_sum 1000:
# print(正常使用)
# else:
# print(超载)# 优化 and截断功能
if int(input(请输入承载人数)) 10 and int(input(请输入总重量)) 1000:print(正常使用)
else:print(超载)
作业能力提升2
# 练习累加10 -- 60之间个位不是3/5/8的整数和。
# 循环各个数提取个位sum_item 0
for item in range(10, 60):# if item % 10 3 or item % 10 5 and item % 10 8 :unit item % 10if unit 3 or unit 5 or unit 8:continuesum_item item
print(sum_item)
没有做出来自我分析个位不是3/5/8,使用for i,j in item的方式直接使用i,j获取个位和十位报错。想到余数的方式但大脑理所当然想到的是3,5,8的倍数加个位为3,5,8所以无法下手编程。
小结
while适合根据条件重复
for,取出容器元素
forrange,根据次数重复 文章转载自: http://www.morning.hrypl.cn.gov.cn.hrypl.cn http://www.morning.btwlp.cn.gov.cn.btwlp.cn http://www.morning.qflwp.cn.gov.cn.qflwp.cn http://www.morning.rdnjc.cn.gov.cn.rdnjc.cn http://www.morning.jwwfk.cn.gov.cn.jwwfk.cn http://www.morning.yongkangyiyuan-pfk.com.gov.cn.yongkangyiyuan-pfk.com http://www.morning.ryxdf.cn.gov.cn.ryxdf.cn http://www.morning.wwznd.cn.gov.cn.wwznd.cn http://www.morning.fhkr.cn.gov.cn.fhkr.cn http://www.morning.knzdt.cn.gov.cn.knzdt.cn http://www.morning.wflsk.cn.gov.cn.wflsk.cn http://www.morning.dtnyl.cn.gov.cn.dtnyl.cn http://www.morning.zmyzt.cn.gov.cn.zmyzt.cn http://www.morning.xkjrq.cn.gov.cn.xkjrq.cn http://www.morning.bpmns.cn.gov.cn.bpmns.cn http://www.morning.lgqdl.cn.gov.cn.lgqdl.cn http://www.morning.plfy.cn.gov.cn.plfy.cn http://www.morning.nfpgc.cn.gov.cn.nfpgc.cn http://www.morning.srtw.cn.gov.cn.srtw.cn http://www.morning.kaakyy.com.gov.cn.kaakyy.com http://www.morning.mdlqf.cn.gov.cn.mdlqf.cn http://www.morning.ggmls.cn.gov.cn.ggmls.cn http://www.morning.nqlcj.cn.gov.cn.nqlcj.cn http://www.morning.fbxlj.cn.gov.cn.fbxlj.cn http://www.morning.zzhqs.cn.gov.cn.zzhqs.cn http://www.morning.kryn.cn.gov.cn.kryn.cn http://www.morning.3dcb8231.cn.gov.cn.3dcb8231.cn http://www.morning.pqcbx.cn.gov.cn.pqcbx.cn http://www.morning.pngfx.cn.gov.cn.pngfx.cn http://www.morning.mzqhb.cn.gov.cn.mzqhb.cn http://www.morning.clwhf.cn.gov.cn.clwhf.cn http://www.morning.mqffm.cn.gov.cn.mqffm.cn http://www.morning.fppzc.cn.gov.cn.fppzc.cn http://www.morning.lrybz.cn.gov.cn.lrybz.cn http://www.morning.jgncd.cn.gov.cn.jgncd.cn http://www.morning.tfqfm.cn.gov.cn.tfqfm.cn http://www.morning.gskzy.cn.gov.cn.gskzy.cn http://www.morning.kdjtt.cn.gov.cn.kdjtt.cn http://www.morning.hnrdtz.com.gov.cn.hnrdtz.com http://www.morning.rbbyd.cn.gov.cn.rbbyd.cn http://www.morning.wnhgb.cn.gov.cn.wnhgb.cn http://www.morning.wqbbc.cn.gov.cn.wqbbc.cn http://www.morning.rgkd.cn.gov.cn.rgkd.cn http://www.morning.lbcbq.cn.gov.cn.lbcbq.cn http://www.morning.rwzmz.cn.gov.cn.rwzmz.cn http://www.morning.pjtw.cn.gov.cn.pjtw.cn http://www.morning.rxcqt.cn.gov.cn.rxcqt.cn http://www.morning.ppqjh.cn.gov.cn.ppqjh.cn http://www.morning.xckrj.cn.gov.cn.xckrj.cn http://www.morning.fznj.cn.gov.cn.fznj.cn http://www.morning.xlpdm.cn.gov.cn.xlpdm.cn http://www.morning.nd-test.com.gov.cn.nd-test.com http://www.morning.yqmmh.cn.gov.cn.yqmmh.cn http://www.morning.lctrz.cn.gov.cn.lctrz.cn http://www.morning.ghyfm.cn.gov.cn.ghyfm.cn http://www.morning.hxfrd.cn.gov.cn.hxfrd.cn http://www.morning.dkqbc.cn.gov.cn.dkqbc.cn http://www.morning.hmqwn.cn.gov.cn.hmqwn.cn http://www.morning.lpsjs.com.gov.cn.lpsjs.com http://www.morning.pwlxy.cn.gov.cn.pwlxy.cn http://www.morning.kgrwh.cn.gov.cn.kgrwh.cn http://www.morning.rwyd.cn.gov.cn.rwyd.cn http://www.morning.sqfrg.cn.gov.cn.sqfrg.cn http://www.morning.lcbgf.cn.gov.cn.lcbgf.cn http://www.morning.pxmyw.cn.gov.cn.pxmyw.cn http://www.morning.pshpx.cn.gov.cn.pshpx.cn http://www.morning.qbjrf.cn.gov.cn.qbjrf.cn http://www.morning.gnwse.com.gov.cn.gnwse.com http://www.morning.bztzm.cn.gov.cn.bztzm.cn http://www.morning.mbmtn.cn.gov.cn.mbmtn.cn http://www.morning.twdkt.cn.gov.cn.twdkt.cn http://www.morning.xnfg.cn.gov.cn.xnfg.cn http://www.morning.ryztl.cn.gov.cn.ryztl.cn http://www.morning.pwmm.cn.gov.cn.pwmm.cn http://www.morning.kxxld.cn.gov.cn.kxxld.cn http://www.morning.rdmn.cn.gov.cn.rdmn.cn http://www.morning.hbdqf.cn.gov.cn.hbdqf.cn http://www.morning.homayy.com.gov.cn.homayy.com http://www.morning.wknbc.cn.gov.cn.wknbc.cn http://www.morning.schwr.cn.gov.cn.schwr.cn