python-打印简单公司员工信息表
要求,输入name不为空,输入次数最多3次,3次后跳出程序;

知识点:

raw_input

str转int

whil

if elif else continue break

for

导入模块

引用变量值

格式化输出

vim

#!/usr/bin/env python
import sys
user_name = "carson"
this_year = 2014
counter  = 0
while True:
    if counter < 3:
        name = raw_input("please input your name:").strip()
        if len(name) == 0:
            print "empty name , please input your name again!"
            continue
        elif name == user_name:
            pass
            print "welcome to login system!"
        else:
            print "%s is a not valid user, please try again!" % name
            counter = counter + 1
            continue
        break
    else:
        print "Your input 3 times!"
        sys.exit()
    break
age = int(raw_input("How old are you?"))
sex = raw_input("please input your sex:")
hobby = raw_input("Do you hava any hobbies?")
information =  '''Information of company staff 
    Name :%s
    Age  :%d
    Sex  :%s
    Hobby:%s
    ''' % (name,age,sex,hobby)
print information
输入3次,退出程序!
# python carson.by 
please input your name:a
a is a not valid user, please try again!
please input your name:b
b is a not valid user, please try again!
please input your name:c
c is a not valid user, please try again!
Your input 3 times!
输入空白字符,提示一直输入
# python carson.by 
please input your name:
empty name , please input your name again!
please input your name:
empty name , please input your name again!
please input your name:
empty name , please input your name again!
please input your name:
empty name , please input your name again!
please input your name:
empty name , please input your name again!
please input your name:
empty name , please input your name again!
please input your name:
empty name , please input your name again!
please input your name:
empty name , please input your name again!
please input your name:
empty name , please input your name again!

输入正确:

please input your name:carson
welcome to login system!
How old are you?23
please input your sex:M
Do you hava any hobbies?football
Information of company staff 
    Name :carson
    Age  :23
    Sex  :M
    Hobby:football

在判断输入次数的还有一种方法是利用for循环:

#!/usr/bin/env python
import sys
user_name = "carson" while True:
    
        name = raw_input("please input your name:").strip()
        if len(name) == 0:
            print "empty name , please input your name again!"
            continue
        for i range(1,3):
            name = raw_input("please input your name:").strip()
            if name == user_name:
                pass
                print "welcome to login system!"
            else:
                print "%s is a not valid user, please try again!" % name
                continue
            break
        else:
            print "Your input 3 times!"
            sys.exit()
        break
age = int(raw_input("How old are you?"))
sex = raw_input("please input your sex:")
hobby = raw_input("Do you hava any hobbies?")
information =  '''Information of company staff 
    Name :%s
    Age  :%d
    Sex  :%s
    Hobby:%s
    ''' % (name,age,sex,hobby)
print information

python-打印简单公司员工信息表的更多相关文章

  1. python练习程序_员工信息表_基本实例

    python实现增删改查操作员工信息文件,可进行模糊查询: http://edu.51cto.com/lesson/id-13276.html http://edu.51cto.com/lesson/ ...

  2. python作业员工信息表程序(第四周)

    作业需求: 1. 员工信息表程序,实现增删改查操作: 2. 可进行模糊查询,语法至少支持下面3种: select name,age from staff_table where age > 22 ...

  3. python练习题-员工信息表

    周末大作业:实现员工信息表文件存储格式如下:id,name,age,phone,job1,Alex,22,13651054608,IT2,Egon,23,13304320533,Tearcher3,n ...

  4. python基础之员工信息表作业

    周末大礼包 文件存储格式如下: id, name, age, phone, job 1, Alex, 22, 13651054608, IT 2, Egon, 23, 13304320533, Tea ...

  5. day12 python作业:员工信息表

    作业要求: 周末大作业:实现员工信息表文件存储格式如下:id,name,age,phone,job1,Alex,22,13651054608,IT2,Egon,23,13304320533,Tearc ...

  6. python's sixteenth day for me 员工信息表

    import os user_dic = { 'username':None, 'password':None, 'login':True } flag = False name_list = ['i ...

  7. python-查询员工信息表

    python查询员工信息表 基本要求: 用户可以模糊查询员工信息 显示匹配了多少条,匹配字符需要高亮显示 代码: #!/usr/env python #coding:utf-8 import time ...

  8. python3 员工信息表

    这是最后一条NLP了......来吧 十二,动机和情绪总不会错,只是行为没有效果而已 动机在潜意识里,总是正面的.潜意识从来不会伤害自己,只会误会的以为某行为可以满足该动机,而又不知道有其他做法的可能 ...

  9. day21 05 员工信息表

    day21 05 员工信息表 假设有一个员工信息表,里面有每个员工的名字,id,年龄,电话,还有他们所作的工作,而有时候我们并不需要所有的信息,而想根据某些条件,寻找符合条件即可,即筛选, 比如想要筛 ...

随机推荐

  1. spoj 2319 BIGSEQ - Sequence

    You are given the sequence of all K-digit binary numbers: 0, 1,..., 2K-1. You need to fully partitio ...

  2. [BZOJ 2821] 作诗(Poetize) 【分块】

    题目链接:BZOJ - 2821 题目分析 因为强制在线了,所以无法用莫队..可以使用分块来做. 做法是,将 n 个数分成 n/x 个块,每个块大小为 x .先预处理出 f[i][j] ,表示从第 i ...

  3. nosql db and javascript performance

    http://blog.csdn.net/yiqijinbu/article/details/9053467 http://blog.nosqlfan.com/tags/javascript http ...

  4. Unity3d 读取网络xml

    Unity3d 读取网络xml Unity3d 读取网络xml,这个xml文件需要不包含BOM信息,可以用UltraEdit打开xml文件,并且另存为的时候,选择不包含BOM的utf-8格式存储!

  5. ubuntu進入dos界面命令 ubuntu進入圖形界面命令

    切换界面: ctrl + alt + F1是切到终端模式 Alt+F7 切到图形界面

  6. 我的VSTO之路:序

    原文:我的VSTO之路:序 VSTO是微软提供给.Net开发人员的一个接口,通过他我们可以对Office程序做一些处理.但是这个接口并不尽善尽美,相比微软的很多其他产品,VSTO的稳定性并不好,相关的 ...

  7. 连接各种数据库神器———DbVisualizer

    作为开发人员,经常会遇到在不同的数据库环境中进行开发或者调试,所以针对每种数据库都要安装对应的客户端,不但要占用硬盘控件而且还要经常切换,无可厚非这是一项头疼并且麻烦的事情.有了DbVisualize ...

  8. 【POJ】2418 Hardwood Species

    简单字典树. #include <cstdio> #include <cstring> #include <cstdlib> #define MAXN 128 ty ...

  9. Unity NGUI的多分辨率适配

    参考链接:http://blog.csdn.net/mfc11/article/details/17681429,作者:CSDN mfc11 1.NGUI默认的适配方式: NGUI默认是适配方式是根据 ...

  10. c语言小练习(蛮好玩的)

    1.求三个数的平均数,要求保留三位小数位 #include <conio.h> #include<stdio.h> int main(){ int a,b,c; float a ...