Page 181 - Computer Science Class 11 With Functions
P. 181
Onnexecutonnofnthenabovenotatement,nPythonnpromptonthenuoernfornthennamenandnwaitonforntheninput.nThenabovenuoen
ofntheninput()nfunctononoeemonoimplenandndevoidnofnanynproblemo.nIfnwenwritenanomallnprogramnthatnneedononlynonen
orntwoninputonandnexecutenitnooonnafternwenarendonenwithnwritngnthenprogram,nthennthionapproachnworkonfine.nButnreal-
lifenprogramonmaynrequirenoeveralninputonandnmaynbenexecutedndayo,nmontho,nornyearonafterntheynarenwritten.nInnouchn
ocenarioo,nitnionnearlynimpoooiblentonrememberntheninputonrequirednbynthenprogram.nInnfact,nmootnofnthenooftwarenionuoedn
bynpeoplenwithoutnanroleninndevelopingnit.nnTherefore,nitnionangoodnpractcentondioplaynanouitablenmeooagenindicatngnthen
inputonrequirednaonilluotratednbelow:
>>> input('Enter name of a Programming language: ')
Enter name of a Programming language: Python
'Python'
>>> language = input('Enter name of a Programming language: ')
Enter name of a Programming language: Python
>>> language
'Python'
input() function reads the text entered by a user until a newline is encountered.
eval()
Theneval()nfunctonnevaluateonanotringnargumentnpaooedntonthenfunctonnandnreturnonthenreoultnofnthenevaluaton.n orn
inotance,nthenfollowingnexpreooionnevaluateo 15+10 andnyieldon25naonanreoult:n
>>> eval('15+10')
25
>>> eval('hello')
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
eval('hello')
File "<string>", line 1, in <module>
NameError: name 'hello' is not defined. Did you mean: 'help'?
Notenthatntonevaluatenhello,nPythonninterpretonhello aonthennamenofnannobjectnandnfindonthatnnonobjectnionaooociatedn
withnthennamenhello,nandnpointonoutnannerror.nHowever,nitnionperfectlynfinentoninterpretnanotringnobjectnaonohownn
below:
>>> eval('"hello"')
'hello'
What will be displayed on executing the statement?
print(eval('15+10')*5)
What will be displayed on executing the statement?
print('15+10'*5)
max()
Thenmax()nfunctonnreturnonthenlargeotnvaluenfromnthenoequencenofnvalueonprovidednaontheninputnargument.nThenoyntaxn
ofnthenfunctonnio:
max(<sequence>) or max(<val1,val2,...,valn>)
orninotance,nthenfollowingnfunctonncallonprintnmaximumnofnthennumericnvalueonandnlargeotnotringnfromnthenvalueon
providednaontheninput:
>>> max(2,0,-4,19.0,36,8)
36
>>> max('Arushi','Muskan','Sameer','Ayana')
'Sameer'
Introductonnton unctono 179

