当用户输入密码时候,如果输入正确会输出welcom user login,如果输入错误会输出invalid username or password
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
#!/usr/bin/env python # -*- coding:utf-8 -*- import getpass
_username = "xcn"
_password = "admin"
username = input ( "username:" )
password = getpass.getpass( "password:" )
print (username, password)
if _username = = username and _password = = password:
print ( "welcome user {name} login ..." . format (name = username))
else :
print ( "invalid username or password!" )
ce |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
#!/usr/bin/env python # -*- coding:utf-8 -*- age_of_xcn = 20
guess_age = int ( input ( "guess age:" ))
if guess_age = = age_of_xcn:
print ( "yes,you got it" )
elif guess_age > age_of_xcn:
print ( "think smaller" )
else :
print ( "think bigger" )
执行结果: guess age: 12
think bigger guess age: 22
think smaller |
本文转自 baishuchao 51CTO博客,原文链接:http://blog.51cto.com/baishuchao/1932908