Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #55092

Re: VERY BASIC HELP

From John Gordon <gordon@panix.com>
Newsgroups comp.lang.python
Subject Re: VERY BASIC HELP
Date 2013-09-30 17:25 +0000
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <l2cc6q$11s$1@reader1.panix.com> (permalink)
References <380132bc-bc9c-4d57-95d8-dc01f26f47a5@googlegroups.com>

Show all headers | View raw


In <380132bc-bc9c-4d57-95d8-dc01f26f47a5@googlegroups.com> vignesh.harikrishna@gmail.com writes:

> c=int(raw_input("How many numbers do you want to work? (Min. 2 Max. 3)"))
> if c==2:
>     x=int(raw_input("Enter the first number to be worked"))
>     y=int(raw_input("Enter the second number to be worked"))
> elif c==3:
>     x=int(raw_input("Enter the first number to be worked"))
>     y=int(raw_input("Enter the second number to be worked"))
>     z=int(raw_input("Enter the third number to be worked"))
> else:
>     print "Invalid input.";raw_input("Press <enter> to close this window");exit    
> p=int(raw_input("Do you want to divide, subtract, add or multiply these numbers? (1=divide, 2=subtract, 3=add, 4=multiply)"))
> if p==1 and c==2:
>     print "The result is : ";x/y
> elif p==1 and c==3:
>     print "The result is :";x/y/z
> elif p==2 and c==2:
>     print "The result is :";x-y
> elif p==2 and c==3:
>     print "The result is :";x-y-z
> elif p==3 and c==2:
>     print "The result is :";x+y
> elif p==3 and c==3:
>     print "The result is :";x+y+z
> elif p==4 and c==2:
>     print "The result is :";x*y
> elif p==4 and c==3:
>     print "The result is :";x*y*z   
> else:
>     print "Invalid Input.";raw_input("Press <enter> to close this window")

> That is my program. These are the problems I am having : 

> 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.

That's because your code is this:

    exit

instead of this:

    exit()

In other words, you're referring to the exit function, but not actually
calling it.

> 2. If all values are entered correctly, the result does not display. It
> shows up as "The result is :" and just blank.

That's because you're using a semicolon after the print statement.

This code is really two completely separate statements:

    print "The result is : ";x/y

It prints the message and then, as a separate action, it calculates the
value of x/y (and then throws that value away, because it isn't assigned
anywhere.)

Use a comma instead of a semicolon, like this:

    print "The result is : ", x/y

-- 
John Gordon                   A is for Amy, who fell down the stairs
gordon@panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

VERY BASIC HELP vignesh.harikrishna@gmail.com - 2013-09-30 09:55 -0700
  Re: VERY BASIC HELP Chris Angelico <rosuav@gmail.com> - 2013-10-01 03:07 +1000
  Re: VERY BASIC HELP John Gordon <gordon@panix.com> - 2013-09-30 17:25 +0000
  Re: VERY BASIC HELP vignesh.harikrishna@gmail.com - 2013-09-30 10:50 -0700
    Re: VERY BASIC HELP Joel Goldstick <joel.goldstick@gmail.com> - 2013-09-30 15:02 -0400
    Re: VERY BASIC HELP rusi <rustompmody@gmail.com> - 2013-10-01 10:12 -0700
    Re: VERY BASIC HELP Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-10-01 18:25 +0100

csiph-web