Trying to get
function call but I can not get it to print. Please help here this code is:
def foo (): name = input ('> & gt;') Less (). Split () for the item in the name: if name == foo: ('Foo here!') Else: bar (def define): name = input ('> & gt;') Less (). Split () for the name in the name: if name == bar: print ('bar here!') Def start (print: 'Welcome home') name = input foo () Start ()>
both
print ('foo here!')andprint (' Bar here! ')was not executed because Boolean expressionname == fooandnames == timesis evaluated on the wrong in most cases. For example, under the definitionfoo (), the first element ofname == foo,namein Boolean expressionfoo. Thefooobject functionsfoo ()(usually used for debugging purposes) gives the corresponding string representation that you can actually tryfoo ( ) Can printby typingprint (foo)andlist nameinfoo ()(my case In its& lt; function fu 0x7fad58f35d40 & gt;- this will probably differ on your machine). This will evaluatename == fooand hence the result will be executed by theprint ('foo here!'). It is being said that ,:< P> The first element in your
![]()
namelist is assigned to theitemvariable, then the body of the loop is executed. After executing the body, the second element in the list is specified in thenameto the variableitembefore the body of the loop is re-implemented. This process continues until there is no other element in thenamelist. Now to executeprint ('foo here!')for the order, the Boolean expression must be correctly evaluated in your statementHere is an example where
Print ('foo here!') Will execute when the user foo will run after running the program.def foo (): name = input ('> gt; & gt;') Less (). For item in the split () name: if item == 'foo': print ('foo here!') Else: bar () def bar (): name = input ('> gt; & gt;') Name for item (lower) Split (): If the item == 'bar': print ('bar here!') Print ('welcome home') Foo ()
foo () , the first element of the list is compared withnamefoo, thus conditionif name == 'foo'is found here is a sample of execution:[fairs @ arch python] $ ./foobar.py welcome home & gt; & Gt; Foo foo here!
Comments
Post a Comment