python

本文介绍了一个使用Python实现的基本计算器功能及用户管理系统的程序。该程序支持加减乘除运算,并具备用户注册、登录验证、展示用户列表及删除用户的管理功能。

#!/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]*'

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值