模拟exit()退出命令实现

1.当输入exit命令是退出程序,如果输入其他的就打印====>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
方法一<br>while True:
    username=input("请输入你的用户名:>>>")
    password=input("请输入你的密码:>>>")
    if username=='zhanghaiyan' and password=='123456':
        print('login successful')
        while True:
            cmd=input("请输入命令:>>>")
            if cmd=='exit':
                break
            print("====>",cmd)
        break
     
# 方法二:
tag=True
while tag:
    username=input("请输入你的用户名:>>>")
    password=input("请输入你的密码:>>>")
    if username=='zhanghaiyan' and password=='123456':
        print('login successful')
        while tag:
            cmd=input("请输入命令:>>>")
            if cmd=='exit':
                tag=False
                continue
            print("====>",cmd)
 
# 方法三:
tag=True
while tag:
    username=input("请输入你的用户名:>>>")
    password=input("请输入你的密码:>>>")
    if username=='zhanghaiyan' and password=='123456':
        print('login successful')
        while tag:
            cmd=input("请输入命令:>>>")
            if cmd=='exit':
                tag=False
            else:
                print("====>",cmd)

 

posted @ 2018-02-02 22:39  East~L  阅读(132)  评论(0)    收藏  举报