python 练习一

1. 你理解的python是什么?为什么会使用python?

python是一个脚本语言,python 拥有强大的第三方库,开发的周期短,并且可移植较强

2. 解释python第一行怎么写?写的内容是做什么的?怎么写可移植性强?为什么?

#!/usr/bin/python       

#!/usr/bin/env python

第一行写的内容都是指定解释器的路径,不同的是,第二种制定方式能够适应不同的安装方式所安装的解释的路径

3. 解释编码格式ASCII,Unicode和utf-8的不同点?

ASCII 是美国制定的编码,只适用于英文字母,不支持其他语言的文字,Unicode能够适用于其它各种语言的文字,utf-8同样能够支持各种文字,而且能根据不同的符号而变化字节长度。

4. raw_input和input的区别

raw_input 是输入字符型 input 是输入整型

5. 三个双引号号(或者三个单引号的)可以用来做什么?

三个双引号可以编辑内容的格式 ,三个单引号可以多行注释

6. python格式化输出(包含变量)的方法有哪些?并举例列出?

[root@news ipython]# python
Python 2.7.5 (default, Oct 11 2015, 17:47:16) 
[GCC 4.8.3 20140911 (Red Hat 4.8.3-9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> A = "word"
>>> print "hello" ,A
hello word
>>> 

>>> A= 1
>>> B= 2
>>> print "the numner is",A,B
the numner is 1 2
>>> 
>>> A=1
>>> B=2
>>> print "the first num is %d ,the second num is %d" %(A,B)
the first num is 1 ,the second num is 2
>>> 

>>> A=1
>>> B= "hello"
>>> print "the num is {} ,the string is {} " .format(A,B)
the num is 1 ,the string is hello 
>>> 

编程练习

    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:.py
date:2017/8/25 0:06
author:    peak
description:
"""
for i in range(1,4):

    user=raw_input("login name:")
    password=raw_input("password:")
    if user =="root" and password == "westos" :
        print "login ok"
        exit()
    elif user =="root":
        print "password is not ok"
    else:
        print "user is not exit"
print "count is bigger than 3"


测试一

测试二

  • 编写乘法表
#!/usr/bin/env python
#coding:utf-8
"""
file:.py
date:2017/8/25 0:06
author:    peak
description:
"""
for i in range(1,10):
    for n in range(1,i+1):
        print "{}*{}={}" .format(i,n,i*n)
    print " "

这里写图片描述

这里写图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值