作业

来源:互联网 发布:mv录制软件 编辑:程序博客网 时间:2024/05/22 10:55

问答

  1. 你理解的python是什么?为什么会使用python?
    1)一种编程语言,具有高效性;
    2)因为我想学技术。
  2. 解释python第一行怎么写?写的内容是做什么的?怎么写可移植性强?为什么?
    1)#!/usr/bin/python
    #!/usr/bin/env python
    2)解释器
    3)#!/usr/bin/env python
    4)引用环境变量里的自定义Python版本,所以具有较强的可移植性!
  3. 解释编码格式ASCII,Unicode和utf-8的不同点?
    ASCII:美国人发明了计算机,1个字节(8位)去存储一个英文字符,2^8=256;
    Unicode:2个字节(16位)去存储一个字符,2^16,65536;
    # GB2312:
    utf-8:在编程过程中,英文多,中文少。如果是英文字符,就用一个字节去存储;如果是中文用3个字节去存储;
  4. raw_input和input的区别?
    raw_input输入的内容为字符类型;
    input为数值类型。
  5. 三个双引号号(或者三个单引号的)可以用来做什么?
    注释
  6. python格式化输出(包含变量)的方法有哪些?并举例列出?
    这里写图片描述
    这里写图片描述
    这里写图片描述
    这里写图片描述

编程练习:

  1. 用户登陆v1:
    1). 假设系统中的用户名”root”,密码为”westos”;
    2). 如果用户输入用户名和密码均正确显示”login ok”
    如果用户名错误,显示”user is not exist”
    如果密码错误,显示”password is no ok”
    3). 只有三次登陆机会,超过三次,显示”count is bigger than 3”
#!/usr/bin/env python#coding:utf-8"""file:westos.pydate:2017-08-24 11:33 PMauthor:lihangdesc:"""username = raw_input('username:')password = raw_input('password:')if username == 'root' and password != 'westos':    print ('password is no ok !')elif username != 'root' and password == 'westos':    print ('user is not exist !')elif username == 'root' and password == 'westos':    print ('login ok !')#     i = True#     while True:#         num += 1# else:#     if i == True:#         exit(0)#     elif num > 3:#         print ('count is bigger than 3 !')

这里写图片描述
这里写图片描述
这里写图片描述
2. 编写乘法表;

#!/usr/bin/env python#coding:utf-8"""file:haha.pydate:2017-08-24 11:25 PMauthor:lihangdesc:"""for x in range(1,10):    for y in range(1,x+1):        print y,'x',x,'=',x*y,'\t',    print '\n'

这里写图片描述

原创粉丝点击