VERY BASIC HELP

Chris Angelico rosuav at gmail.com
Mon Sep 30 13:07:36 EDT 2013


On Tue, Oct 1, 2013 at 2:55 AM,  <vignesh.harikrishna at gmail.com> wrote:
>     print "Invalid input.";raw_input("Press <enter> to close this window");exit

> 1. Even if c is not 2 or 3, the program continues, as if it received a valid input, it does not exit as I have tried to code it to.

In Python, exit isn't a statement, it's a function. So you need to write:

exit()

to actually terminate.

> elif p==3 and c==3:
>     print "The result is :";x+y+z
> 2. If all values are entered correctly, the result does not display. It shows up as "The result is :" and just blank.

The semicolon ends the print statement, and then you simply evaluate
and do nothing with the sum. Try a comma instead - that'll make it a
second argument to print, so it'll be printed out as you expect.

Thank you for making your problem so clear. You've given your code,
and you've said exactly what it's doing that you don't expect. I
really appreciate that! But one thing I would ask: Next time, please
consider your subject line. That's the first chance you have to grab
someone's attention - "VERY BASIC HELP" doesn't say _what_ you need
help with. :) Your post makes a nice change from some I've seen,
though...

Have fun, happy Pythoning!

ChrisA



More information about the Python-list mailing list