Python uses raw_input to read input values _python

Source: Internet
Author: User

In this paper, the usage of raw_input in Python is introduced in detail, and the data can be read by using Raw_input, which is convenient for the bundle console. Examples of specific uses are as follows:

1. Input string

#13222319810101 * * *
NID = ' while
1:
  NID = raw_input ("Input your id plz")
  if Len (NID)!= len ("1322231981 0101**** "):
    print ' wring length of id,input again '
  else:
    break
 
print ' Your ID is%s '% (NID)

2. Input integer

nage = Int (raw_input ("Input your Age plz:\n")
if nage > 0 and Nage <:
  print ' thanks! '
else:
  print ' bad age '
print ' your '%d\n '% nage

3. Input floating-point type

Fweight = 0.0
fweight = float (raw_input ("Input your Weight\n"))
print ' Your weight is%f '% fweight

4. Enter 16 data

Nhex = Int (raw_input (' Input hex value (like 0x20): \ n ')
print ' Nhex =%x,noct =%d\n '% (Nhex,nhex)

5. Enter 8 data

noct = Int (raw_input (' Input Oct value (like 020): \ n '), 8)
print ' noct =%o,ndec =%d\n '% (noct,noct)

This article examples of Python beginners have a certain learning value, interested readers can start debugging run a sample of this article to deepen the understanding of raw_input usage.

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.