1.2.1.1. Normal Method ¶
~cpp print 'problem 1-1' print 'type 3 values' v1 = input() v2 = input() v3 = input() print 'max=',max(v1, v2, v3) print 'min=',min(v1, v2, v3) print 'problem 1-2' print 'type 10 values ' vv1 = input() vv2 = input() vv3 = input() vv4 = input() vv5 = input() vv6 = input() vv7 = input() vv8 = input() vv9 = input() vv10 = input() print 'max=',max(vv1,vv2,vv3,vv4,vv5,vv6,vv7,vv8,vv9,vv10) print 'min=',min(vv1,vv2,vv3,vv4,vv5,vv6,vv7,vv8,vv9,vv10)
ref input eval 거까. 게 . 그 게 . --개
~cpp input( [prompt]) Equivalent to eval(raw_input(prompt)). Warning: This function is not safe from user errors! It expects a valid Python expression as input; if the input is not syntactically valid, a SyntaxError will be raised. Other exceptions may be raised if there is an error during evaluation. (On the other hand, sometimes this is exactly what you need when writing a quick script for expert use.) If the readline module was loaded, then input() will use it to provide elaborate line editing and history features. Consider using the raw_input() function for general input from users.
~cpp >>> input() 1+2 3
1.2.1.2. Using Recursion ¶
~cpp
def myproc(count,mx,mn):
val = int(raw_input())
if count != 0 :
if mx == None :
return myproc(count-1, val, val)
else :
return myproc(count-1, max(mx, val),min(mn,val))
else :
return max(mx,val),min(mn,val)
print 'problem 1-1'
max1,min1=myproc(2,None,None)
print 'max=',max1,'min=',min1
print 'problem 1-2'
max2,min2=myproc(9,None,None)
print 'max=',max2,'min=',min2
1.2.1.3. Using Iteration ¶
~cpp
def iterproc(count):
mx=None
mn=None
for i in range(0,count):
val = int(raw_input())
if mx == None:
mx = val
mn = val
else :
mx = max(mx,val)
mn = min(mn,val)
return mx,mn
print 'problem 1-1'
max1,min1=iterproc(3)
print 'max=',max1,'min=',min1
print 'problem 1-2'
max2,min2=iterproc(10)
print 'max=',max2,'min=',min2
1.2.2.1.1. Using List Comprehension ¶
~cpp
def printMaxMin(cnt):
inputList = [ input() for i in range(cnt) ]
print 'max=%d, min=%d'%(max(inputList),min(inputList))
print 'problem 1-1'
printMaxMin(3)
print 'problem 1-2'
printMaxMin(10)
1.2.2.1.2. Using map ¶
~cpp
def printMinMax(cnt):
inputList = map(lambda x:input(),range(cnt))
print 'max=%d, min=%d'%(max(inputList),min(inputList))
print 'problem 1-1'
printMinMax(3)
print 'problem 1-2'
printMinMax(10)
1.2.2.2. Using Generator for input ¶
~cpp
def inputNum(v=[]):
while True:
v.append(input())
yield max(v),min(v)
maxMin=()
print 'problem 1-1'
inputNum_gen=inputNum()
for i in range(3):
maxMin=(inputNum_gen.next())
print 'max=%d, min=%d'%maxMin
inputNum_gen=inputNum()
print 'problem 1-2'
for i in range(10):
maxMin=(inputNum_gen.next())
print 'max=%d, min=%d'%maxMin
1.3.2. ¶
~cpp
inNums = [ int(i) for i in raw_input('input numbers with space:\n').split() ]
print 'max=%d min=%d' % (max(inNums),min(inNums))
1.3.3. ¶
~cpp
a = raw_input()
news = []
for i in a.split():
news.append(int(i))
print max(news), min(news)
- () 간; -
경 개기 map . Haskell 고 List Comprehension 고 Genrator Expression . 그고 print , 그 . print 과 과, . --NeoCoin
~cpp a = raw_input() news = map(lambda x:int(x), a.split()) print max(news), min(news)











.png)