Tips for reading input values from Python

Source: Internet
Author: User

An application in the Python programming language can read input values. This is a very important application technology used in actual operations. Here, we will give you a detailed introduction to the application skills related to reading input values from Python, hoping to help you.

The following describes the usage of python raw_input. Using raw_input can easily read data in the cluster console.

Operation Method for reading input values in Python 1. input string

 
 
  1. #13222319810101****  
  2. nID = '' 
  3. while 1:  
  4. nID = raw_input("Input your id plz")  
  5. if len(nID) != len("13222319810101****"):  
  6. print 'wring length of id,input again'  
  7. else:  
  8. break  
  9. print 'your id is %s' % (nID) 

Operation Method for reading input values in Python 2. Input integer

 
 
  1. nAge = int(raw_input("input your age plz:\n"))  
  2. if nAge > 0 and nAge < 120: 
  3. print 'thanks!'  
  4. else:  
  5. print 'bad age'  
  6. print 'your age is %d\n' % nAge 

3. Input floating point type

 
 
  1. fWeight = 0.0  
  2. fWeight = float(raw_input("input your weight\n"))  
  3. print 'your weight is %f' % fWeight 

Python Operation Method for reading input values 4. Input hexadecimal data

 
 
  1. nHex = int(raw_input('input hex value(like 0x20):\n'),16)  
  2. print 'nHex = %x,nOct = %d\n' %(nHex,nHex) 

Operation Method for reading input values in Python 5. Input octal data

 
 
  1. nOct = int(raw_input('input oct value(like 020):\n'),8)  
  2. print 'nOct = %o,nDec = %d\n' % (nOct,nOct) 

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.