Python USES raw_input to read input values
- 2020-04-02 13:59:05
- OfStack
This article describes the use of raw_input in python in more detail. Using raw_input makes it easy to read data into the cluster console. Specific usage examples are as follows:
1. Enter a string
#13222319810101****
nID = ''
while 1:
nID = raw_input("Input your id plz")
if len(nID) != len("13222319810101****"):
print 'wring length of id,input again'
else:
break
print 'your id is %s' % (nID)
Enter an integer
nAge = int(raw_input("input your age plz:n"))
if nAge > 0 and nAge < 120:
print 'thanks!'
else:
print 'bad age'
print 'your age is %dn' % nAge
3. Enter floating point
fWeight = 0.0
fWeight = float(raw_input("input your weightn"))
print 'your weight is %f' % fWeight
4. Enter hexadecimal data
nHex = int(raw_input('input hex value(like 0x20):n'),16)
print 'nHex = %x,nOct = %dn' %(nHex,nHex)
5. Enter hexadecimal data
nOct = int(raw_input('input oct value(like 020):n'),8)
print 'nOct = %o,nDec = %dn' % (nOct,nOct)
The examples in this article are useful for Python beginners, and interested readers can debug and run the examples to gain a better understanding of the use of raw_input.