python学习1-基础

Tab键补全设置:

使用ubuntu12.03中的python2.7

在/usr/lib/python.27/dist-packages/ 下新建 vi tab.py

root@meng-VirtualBox:/usr/lib/python2.7/dist-packages# vi tab.py

# python startup file
import sys
import readline
import rlcompleter
#import atexit
import os
# tab completion
readline.parse_and_bind(' tab: complete')
# history file
histfile = os.path.join(os.environ['HOME'],'.pythonhistory')
#try:
#    readline.read_history_file(histfile)
#except IOError
#    pass
#atexit.register(readline.write_history_file,histfile)


在python里面引入import有三种方法

Import moduleName  

如  import os

From module import sayHi

  如from os import system

Import moduleName as new Name 

如import SocketServer as SS


下面我们开始学习 新建input.py

#!/usr/bin/env python

this_year = 2013
name = raw_input("please input your name:")
age = int(raw_input("how old are you?")) //输入字符串转为int类型


print "hello, ",name,'\n'
print "you are ",age,'years old!'
print "so you were born in: ", this_year - age

执行 python input.py



#!/usr/bin/env python
this_year = 2013
name = raw_input("please input your name:")
age = int(raw_input("how old are you?"))
sex = raw_input("please input your sex:")
dep = raw_input("which department:")

//将输入作为参数
message = ''' Information of the company staff:
        Name: %s
        Age : %d
        Sex : %s
        Dep : %s
        ''' % (name, age, sex , dep)
print message


print "hello, ",name,"\n"
print "you are ",age,"years old!"
print "so you were born in: ", this_year - age

#!/usr/bin/env python
import sys
this_year = 2013
true_name = "meng"
true_password = "99999"
#counter = 0
while True:
   #if counter < 3:
   name = raw_input("please input your name:").strip()
   if len(name) == 0:
                print " empty name,try again!"
                continue
   for i in range(1,3):
        name = raw_input("please input your name:").strip()
        if name == true_name:
                print  "Welcome to login,%s" %name
        else:
                print "%s is not a valid user,please try again!" % name
                #counter+=1
                continue
        break
   else:
        print " too many error"
        sys.exit()
   break
age = int(raw_input("how old are you?"))
sex = raw_input("please input your sex:")
dep = raw_input("which department:")
password = raw_input("please input you password:")
message = ''' Information of the company staff:
        Name: %s
        Age : %d
        Sex : %s
        Dep : %s
        ''' % (name, age, sex , dep)
print message


if name != true_name:
        print "you input name is error!"
else:
        print "you input name is ",name," is right!"
if password != true_password:
        print "you input password is error!"
else:
        print "you input password is ",password," is right!"
if age < 28 :
         print "Congratulations! you've got half day's public holiday!"
elif age == 28:
         print "As you are at the right age, i am think about to give 2 hours holiday!"
else:
         print "Sorry, you are too old to have this holiday! get back to work!"


print "hello, ",name,"\n"
print "you are ",age,"years old!"
print "so you were born in: ", this_year - age


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值