[pythonvis] Re: print"Hello world."

  • From: "Charles Rivard" <wee1sman@xxxxxxxxxx>
  • To: <pythonvis@xxxxxxxxxxxxx>
  • Date: Thu, 1 May 2014 22:36:13 -0500

"pritn"?  Would that cause an error?  Shouldn't it be "print"?

---
Be positive! When it comes to being defeated, if you think you're finished, you! really! are! finished! ----- Original Message ----- From: "Octavian Rasnita" <orasnita@xxxxxxxxx>
To: <pythonvis@xxxxxxxxxxxxx>
Sent: Tuesday, April 29, 2014 3:34 PM
Subject: [pythonvis] Re: print"Hello world."


Yep, the results are:

D:\>python z8.py
File "z8.py", line 2
pritn "Goodbye world!"
^
SyntaxError: invalid syntax
D:\>

So the program is not ran.

As I said, first the program is checked for syntax, is compiled in memory if the syntax is correct and if it has a syntax error no line is executed from it.

Then it is ran. But just like in any program made in any other language, there may appear runtime errors like no free space on hard disk, no memory, divide by zero etc. All these things can't be known at compile time. Probably a program asks to user to type 2 numbers and then divide one with the other.
The user can type anything including 0 or strings.
If the input is not checked then there may appear runtime errors, but that doesn't mean that the program has an error, It is just poorly made because it doesn't check the input data or it doesn't treat all the possible exceptions etc.
(And this can happen in programs made in other languages also.)

--Octavian

----- Original Message ----- From: "James Scholes" <james@xxxxxxxxxxxxx>
To: <pythonvis@xxxxxxxxxxxxx>
Sent: Tuesday, April 29, 2014 9:14 PM
Subject: [pythonvis] Re: print"Hello world."


Richard Dinger wrote:
I was unable to replicate your example.  The first correct print
statement did not print, I only got the error traceback.

I should've realised that a syntax error would prevent the program from
running at all.  However, a traceback does not.  For example, if you run
the following code:

print "Hello world!"
print "Here comes a traceback when we try to divide by zero..."
print 20 / 0

You will see:

Hello world!
Here comes a traceback when we try to divide by zero...
Traceback (most recent call last):
 File "hello.py", line 3, in <module>
   print 20 / 0
ZeroDivisionError: integer division or modulo by zero

You cannot divide a number by zero, so your program crashes and
generates a traceback.  However, as you can see, the file is
syntactically correct, so the statements up to that point will run
without a problem.  Apologies for the error!
--
James Scholes
http://twitter.com/JamesScholes





Other related posts: