LZ,登陆功能有两个子功能:注册与登陆,,初学版如下:
dic = {}a = raw_input("Please input your name...")
b = raw_input("Please 氏陵input your passcode...")
dic[a] = b
print a,dic[a]
print '*******'
c = raw_input("Please input your name...")
if c == a:
d = raw_input("Please input your passcode..."神核顷)
if d == dic[a]:
游陆 print'Welcome back %s '%c,'and your passcode is %s',dic[a]
print 'End ...'
函数版如下:
#!/usr/bin/python# -*- coding: utf-8 -*-
import os
dic = {}
def login(name,passcode):
dic['name'] = name
dic['passcode'] = passcode
def register():
while True:
n = raw_input("Please input your name...")
if n == dic['name']:
p = raw_input("Please input your passcode...")
if p == dic['passcode'] :
print'Welcome back %s '%dic['name'],'and your passcode is %s',dic['passcode']
print 'End ...'
break
else:
print'Your passcode is not correct,try again...'
continue
else:
print"You don't have an account,please register..."
break
a = raw_input("Please input your name...")
b = raw_input("Please input your passcode...")
login(a ,b)
print '**'
register()
字典的使用在面向对象的编程也是很灵活的,常用作可变长度参数传递;推荐一个网址:http://blog.csdn.net/moodytong/article/details/7647684
科科。。
分别输入key和value,key输虚清入回车结束
dic = {}while True:
key = input('启散Input key:')
if key == '':
break
value = input('Input value:')
差旁前 dic[key] = value
for key, value in dic.items():
print(key + ' : ' + value)
代码如下:
Python代码
user = {'admin':'888', 'guest':'999',' test':'000'}
username = input("则或巧请输入账号:")
if username == '':
print("退出系统。")
exit()
password = input("请输入密码:")
if user.get(username):
if password == user[username]:
print("账号密码正确,登陆成功!")
else:
print("账号存在,但密码不正确,登录孙键失败!")
else:
user[username] = password
print("新用户,已团高添加账号密码。新字典如下:\n{0}".format(user))
输出如下:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)