Print simple company employee information table

Source: Internet
Author: User

Required. The input name is not empty. It can be entered three times at most and jumps out of the program three times;

Knowledge point:

Raw_input

STR to int

Whil

If Elif else continue break

For

Import Module

Reference variable value

Format output


Vim

#!/usr/bin/env pythonimport sysuser_name = "carson"this_year = 2014counter  = 0while 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()    breakage = 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
Enter 3 times to exit the program! # Python Carson. By please input your name: AA is a not valid user, please try again! Please input your name: BB is a not valid user, please try again! Please input your name: CC is a not valid user, please try again! Your input 3 times!
Enter a blank character, prompting you to always enter # 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!

Entered correctly:

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


Another way to judge the number of inputs is to use the For Loop:

#!/usr/bin/env pythonimport sysuser_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()        breakage = 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


This article is from the "Siberian wolf" blog, please be sure to keep this source http://kernal.blog.51cto.com/8136890/1429920

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.