Forum Archive

Print function

Berg

Hello,
I'm totally new to the Python language and to Pythonista as well.
I got the Pythonista app for my iPad Air and tried a few thing here and there. Maybe it is my lack of reading all the tutorials or maybe I'm missing something.
It seems the "print" function is not working for me, I mean, not bringing in any results, like it does in a regular computer. As in the example below:

>>> x = 100
>>> y =200
>>>  if:
>>> x + y == 300:
    print ("300")
>>> 300

this result does not show, it all stops in the previous line, print.
Any help would be appreciated.
Thank you.

ccc

Proper syntax is:

if x + y == 300:
    print(x + y)

Under the wrench icon, I would recommend running Analyze (pyflakes) and Check Style to automatically fix code issues.

JonB

Are you doing this in the console, or the editor?

I'll point out that you have a syntax error -- you want

if x+y == 300:
    print("300")

not

if:
   x+y==300:

If you ran this, you will get a syntax error on the if line, and the x+y==300 line.

If you run this in the editor, you may need to slide your finger left to reveal the console -- if I recall correctly, the console is shown automatically the first time something is displayed, but not subsequently.
.
It is also possible that in whatever example you actually ran, maybe your condition was not being satisfied. Try adding

else:
   print('not 300.  x+y=={}'.format(x+y) )

to help you debug.

Or, if you just want to test out print:

print('Hello World!')
Berg

Sorry, I typed that in a hurry, at work; you're right about the syntax error :)
I'm not sure if I'm using the console or editor, but I'll check that out and try the example you suggested and will reply back. Thanks so much for the reply!

Berg

@ccc
Thanks so much! I'll try your recommendations