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
时间: 2024-12-05 15:43:09

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 =

python学习之路 员工信息表(使用文件存储信息)

这里我只实现了员工信息的查询功能,其它的增删改没有实现. 关于员工信息的画了一个简单的流程图 查询流程图 实现的思路: 1.我们得到要查询的语句先把这个语句做简单的处理得到我们想要的数据 condition = input(">>>:").lower().replace(' ', '') # 不区分大小写 "selectname,agewhereage>20" ret = condition.split('where') # ['select

员工信息表作业

# 只实现作业要求的查询功能 # 增加,删除,修改功能为选做题 # 创建员工信息表 # 用户输入查询命令 # 分析用户输入的命令,从命令中提取需要查询的关键字 # 根据关键字来查询内容并输出 staff_table=r'F:\python文件\day21生成器\员工信息表.txt' def select(cmd1): #查询功能 with open(staff_table) as f: path=f.readlines() #读出多行赋值给path staff_l=[{ 'staff_id':

Python 基础 - Day 4 Assignment - 员工信息表程序

作业要求及初步思路 员工信息表程序,实现增删改查操作: ① 可进行模糊查询,语法至少支持下面3种: select name,age from staff_table where age > 22 select * from staff_table where dept = "IT" select * from staff_table where enroll_date like "2013"② 解决方案: sql语句的python解析问题,即将用户输入的sql

Python开发【第xxx篇】函数练习题-----员工信息表

文件存储格式如下: id,name,age,phone,job 1,Alex,22,13651054608,IT 2,Egon,23,13304320533,Tearcher 3,nezha,25,1333235322,IT 现在需要对这个员工信息文件进行增删改查. 基础必做: a.可以进行查询,支持三种语法: select 列名1,列名2,- where 列名条件 支持:大于小于等于,还要支持模糊查找. 示例: select name,age where age>22   #> < s

Python下用List对员工信息表进行模糊匹配

#需求 用户可以模糊查询员工信息 显示匹配了多少条,匹配字符需要高亮度显示 #脚本内容 #!/usr/bin/env python #_*_ coding:utf-8 _*_ while True:         info = 'info.txt'         f = file(info)         search=raw_input('Please Engter You Search Info: ')         for line in f.readlines():       

python Day 4 :员工信息表程序

员工信息表程序,实现增删改查操作: 可进行模糊查询,语法至少支持下面3种: select name,age from staff_table where age > 22 select  * from staff_table where dept = "IT" select  * from staff_table where enroll_date like "2013" 查到的信息,打印后,最后面还要显示查到的条数 可创建新员工纪录,以phone做唯一键,s

python&#39;s sixth day for me 员工信息表

import os user_dic = { 'username':None, 'password':None, 'login':True } flag = False name_list = ['id','name','age','phone','job'] check_conditions = ['>','<','=','like'] def auth(func): def wrapper(*args,**kwargs): with open('user-pwd',encoding='ut

python基础之员工信息表作业

周末大礼包 文件存储格式如下: id, name, age, phone, job 1, Alex, 22, 13651054608, IT 2, Egon, 23, 13304320533, Tearcher 3, nezha, 25, 1333235322, IT 现在需要对这个员工信息文件进行增删改查 一. 基础必做: 可以进行查询,支持三种语法: select 列名1,列名2,… where 列名条件 支持:大于小于等于,还要支持模糊查找. 示例: select name, age wh