python-Printing Simple company employee Information sheet

Source: Internet
Author: User

python-Printing Simple company employee Information sheetrequirements, input name is not empty, enter the number of times up to 3 times, 3 times after jumping out of the program;

Knowledge Points:

Raw_input

STR to int

Whil

If elif else continue break

For

Import Module

Reference variable Value

Formatted 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! 

Input correct:

Please input your name:carsonwelcome to login system!    How old is you?23please input your sex:mdo you hava any hobbies?footballinformation of the company staff Name:carson Age:23 sex:m Hobby:football

Another way to determine the number of inputs is to use a 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

python-Printing Simple company employee Information sheet

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.