Python
  #-*- coding:utf8 -*-(Python文件开头添加)用来解决中文编码问题
    注:Python3以上文件不用加

  一、变量:变量有数字、字母和下划线组成
      1.不能以数字开头
      2.不能是Python保留字/关键字
        <1>保留字就是在Python中预先保留的标识符,这些标识符在Python中具有特定的用途
          不能被程序员作为常规变量名,函数名等使用。
        <2>关键字是Python中目前可以使用的保留字如下:

#程序文件:
import keyword
print(keyword.kwlist)
#运行结果
['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class',
'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global',
'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise',
'return', 'try', 'while', 'with', 'yield']

      3.最好不要和python内置的东西重复(例如内置方法sum())。
  二、条件语句
      <1>if 条件:
          执行代码块
        elif 条件:
          执行代码块
        else:
          执行代码块

      <2>如果if 条件之后不想执行任何代码块
        if 条件:
          pass
        else:
          执行代码块

  三、循环语句
        <1>while 条件:
            执行代码块

        <2>break  #跳出所有循环,

              continue   #跳出本次循环,执行下一次循环

  五、练习

      1、使用while循环输出12356789

#程序程序:
n=1
while n<10:
     if n==4:
      pass
     else:
  print(n)
     n=n+1
#运行结果:
12356789

  

  

      2、求1-100的所有数的和。

#程序程序:
    n=1
    s=0
    while n<100:
     s=s+n
    n=n+1
    print(s)
#运行结果:
  4950

  

      3、输出1-100内的所有奇数。

#程序程序:
    n=1
    s=0
    while n<100:
      if n%2==0:
        pass
      else:
        s=s+n
      n=n+1
    print(s)
#运行结果:
     25

  

      4、输出1-100内的所有偶数。

#程序程序:
n=1
s=0
while n<10:
if n%2==0:
  s=s+n
   else:
  pass
   n=n+1
print(s)
#运行结果:
20

  

      5、求1-2+3-4+5-6 . . .100的所有数的和。

#程序程序:
n = 1
s = 0
while n<10:
if n%2==0:
s=s-n
else:
s=s+n
n=n+1
print(s)
#运行结果:
5

  

最新文章

  1. iOS开发UI篇—直接使用UITableView Controller
  2. 完成一段简单的Python程序,使用函数实现用来判断输入数是偶数还是奇数
  3. 在WINDOWS上通过VAGRANT练习ANSIBLE
  4. 分享一些App常用的模块
  5. lintcode:整数排序||
  6. Oracle数据库之创建表空间与用户
  7. HTML5学习笔记简明版 目录索引
  8. Java 使用AES/CBC/PKCS7Padding 加解密字符串
  9. 201521123001《Java程序设计》第3周学习总结
  10. 用python把一个txt文件中所有逗号,替换成空格?
  11. mysl 常用函数 union all if ifnull exists case when
  12. js apply使用
  13. 使用 ASP.NET SignalR实现实时通讯
  14. day 57 data 插件 表的增删改查
  15. mysql max(),min()的优化
  16. This version of the rendering library is more recent than your version of ADT plug-in. Please update ADT plug-in
  17. Core - Provide an easy way to store administrator and user model differences in a custom store (e.g., in a database)
  18. 20155305乔磊2016-2017-2《Java程序设计》第三周学习总结
  19. Unity QualitySettings.SetQualityLevel 设置质量级别
  20. 【Leetcode】【Hard】Search in Rotated Sorted Array

热门文章

  1. leetcode69. x 的平方根 &#127775;
  2. 树——binary-tree-postorder-traversal(树的后序遍历)
  3. cf2c(模拟退火 步长控制
  4. [NOIP2009]最优贸易(图论)
  5. Jmeter接口测试---加解密
  6. 分布式锁的实现【基于ZooKeeper】
  7. window环境下mysql导入sql文件时报错:ERROR: ASCII &#39;\0&#39; appeared in the statement
  8. 多线程AQS
  9. Task2.设立计算图并自动计算
  10. elasticsearch-head插件添加安全认证