#!/bin/env python
#encoding:utf-8
from __future__ import division
'''
def func(**kwargs):
print type(kwargs)
for k,v in kwargs.items():
print "%s %s" %(k,v)
#func(m=1,n=2)
def
'''
num1 = input('please input a num1:')
num2 = input('please input a num2:')
operator = raw_input('please input operator:')
dic = {
'+':lambda x,y:x+y,
'-':lambda x,y:x-y,
'*':lambda x,y:x*y,
'/':lambda x,y:x/y
}
#for o in dic.keys():
# if o == operator:
# print dic[o](num1,num2)
if operator in dic.keys():
print dic.get(operator)(num1,num2)#!/bin/env python
#encodinig:utf-8:
import getpass
import time
dic = {'nanjidong':'westos','redhat':'westos'}
def menu():
while True:
print '''
(A)ppend users:
(L)ogin users:
(D)elete users:
(S)how users:
(E)xit:
'''
choice = raw_input('input your choice:').upper()
if choice == 'A':
addusers()
elif choice == 'L':
login()
elif choice == 'D':
deleteusers()
elif choice == 'S':
showusers()
elif choice == 'E':
exit(0)
else:
print 'input error'
def addusers():
a = raw_input('please input user:')
if a in dic.keys():
print 'user exist'
else:
print 'please input password:'
passwd1 = getpass.getpass()
dic[a]=[passwd1,time.time()]
print 'adduser success'
def showusers():
for i in dic.keys():
print i
def login():
i = 1
while i < 4:
num1 = raw_input('please input username:')
passwd = getpass.getpass()
if num1 in dic.keys() and dic[num1][0] == passwd:
print 'login success'
if time.time()-dic[num1][1]>14400:
print "Last login:%s"%(time.ctime(dic[num1][1]))
else:
print "hello"
print "You already login %s within 4 hours" %(num1)
break
else:
print "ERROR:username is not exist or password error"
print "you have %d chance"%(4-i)
i+=1
def deleteusers():
print 'input your give up user and passwprd:'
i = raw_input()
if i in dic.keys():
dic.pop(i)
print '%s delete success'%i
else:
print 'input error'
menu()
9-6 文件比较,写一个比较两个文本文件的程序,如果不同,给出第一个不同处的行号和列号。
name1 = raw_input('Enter file name:')
name2 = raw_input('Enter file name:')
a = open(name1,'r')
b = open(name2,'r')
n1 = name1.readlines()
n2 = name2.readlines()
for i in range(1,min(len(n1),len(n2))):
if n1[i] I= n2[i]:
printf i
break
15-6匹配简单的以“www.”开头,以“.com”作结尾的Web 域名,例如:www.yahoo.com. 附加题:使你写的正则表达式还支持其他顶级域名:.edu, .net 等,比如:www.ucsc.edu.
import re
a = ' (www\.)(\w+)\.[com|edu|net]*'
本文介绍了一个使用Python实现的基本计算器功能及用户管理系统的程序。该程序支持加减乘除运算,并具备用户注册、登录验证、展示用户列表及删除用户的管理功能。
46万+

被折叠的 条评论
为什么被折叠?



