wordpress置顶文章,seo竞价是什么意思,网络策划案怎么写,专业的网站建设服务交易平台今天是python学习的第一天#xff0c;收获还是不少的#xff0c;使用的编辑器为python3.7。 第一天学习知识总结#xff1a; 1、编写的第一句python语句#xff1a; print ( hello world ) 2、python的两种执行方式 --python解释器 py文件路径 --python进入解… 今天是python学习的第一天收获还是不少的使用的编辑器为python3.7。 第一天学习知识总结 1、编写的第一句python语句 print ( hello world ) 2、python的两种执行方式 --python解释器 py文件路径 --python进入解释器 实时输入并获取到执行结果 3、python的解释路径 #!/user/bin/env python 4、input 的用法 --永远等待直到用户输入了值就会将输入的值赋值给一个变量 例如 n1 input (请输入用户名) n2 input (请输入密码) print (n1) print(n2) print(....) 5、变量名 组成 字母 数字 下划线 Ps: 数字不能开头 不能是关键字 最好不要和python内置的内容重复 6、条件语句 if基本语句 1、if 条件 代码块 else : 代码块 例如if 11 : print ( Welcome) else : print ( out ) 2、if 支持嵌套 if 11 : if 22 : print (欢迎进入第一会所) else : print (error) else : print (欢迎进入第一道所) 3、if elif inp input (请输入会员等级) if inp 高级会员 : print (美女) elif inp 白金会员 : print (达摩) elif inp 铂金会员 : print (一线小明星) else : print (城管) print (开始服务吧) 补充:pass(条件成立不执行任何语句) if 11 : pass else : print (输入错误) 7、字符串 用引号引起来的内容单引号 双引号 三引号引起的内容谁开头谁结尾不能混用 加法:将两个字符串拼接成一个字符串并赋予一个新的变量 乘法让字符串重复出现 name alex na name * 2 n name na print (n) print (name) print (na) 数字 加法 减法 乘法 除法 次方 余数 a1 10 a2 20 a3 a1 a2 a4 a2 - a1 a5 a1* a2 a6 a1 / a2 a7 a1 ** a2 a8 a1 % a2 #获取余数来判断奇偶数 a9 a1 // a2 #商取整 8、循环 死循环 while 1 1 : print (ok) 9、练习题 (1)使用while循环输入1 2 3 4 5 6 8 9 10 代码如下 n 1 while n 11: if n 7 : pass else: print (n) n n 1 print (-----end-----) 2求1-100的所有数的和 n 1 s 0 while n 101 : s s n n n 1 print ( s ) (3)输出1-100内的所有奇数 n 1 while n 100 : temp n % 2 if temp 0 : pass else : print (n) n n 1 (4)输出1-100内的所有偶数 n 1 while n 101 : temp n % 2 if temp 0 : print (n) else : pass n n 1 (5)求1-23-45...99的所有数的和 n 1 s 0 while n 100 : temp n % 2 if temp 0 : s s - n else : s s n n n 1 print (s) (6)用户登录三次机会重试 自己写的 user_name Mary user_password 123 name input (请输入你的用户登录名:) password input (请输入你的登录密码) count 1 while count 3 : if name ! user_name : input (请输入你的用户登录名:) else: print(用户登录名正确) if password ! user_password : input (请输入你的登录密码) else: print (用户密码正确) count count 1 老师讲的 count 0 while count 3 : user_name input () user_pwd input () if user_name Mary and pwd 123 : print (欢迎登录) break else : print (用户名或密码输入错误) count count 1 print (请修改用户名或密码)转载于:https://www.cnblogs.com/learn-2/p/11229826.html