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


Groups > comp.lang.python > #55088 > unrolled thread

VERY BASIC HELP

Started byvignesh.harikrishna@gmail.com
First post2013-09-30 09:55 -0700
Last post2013-10-01 18:25 +0100
Articles 7 — 6 participants

Back to article view | Back to comp.lang.python


Contents

  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

#55088 — VERY BASIC HELP

Fromvignesh.harikrishna@gmail.com
Date2013-09-30 09:55 -0700
SubjectVERY BASIC HELP
Message-ID<380132bc-bc9c-4d57-95d8-dc01f26f47a5@googlegroups.com>
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.
2. If all values are entered correctly, the result does not display. It shows up as "The result is :" and just blank.

PLEASE HELP

[toc] | [next] | [standalone]


#55090

FromChris Angelico <rosuav@gmail.com>
Date2013-10-01 03:07 +1000
Message-ID<mailman.495.1380560866.18130.python-list@python.org>
In reply to#55088
On Tue, Oct 1, 2013 at 2:55 AM,  <vignesh.harikrishna@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

[toc] | [prev] | [next] | [standalone]


#55092

FromJohn Gordon <gordon@panix.com>
Date2013-09-30 17:25 +0000
Message-ID<l2cc6q$11s$1@reader1.panix.com>
In reply to#55088
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"

[toc] | [prev] | [next] | [standalone]


#55094

Fromvignesh.harikrishna@gmail.com
Date2013-09-30 10:50 -0700
Message-ID<62dfe971-f28a-4b01-a696-b2099dacd91b@googlegroups.com>
In reply to#55088
Thank you both so much! I'll be sure to make more pertinent subject lines now :) Thanks for the detailed explanations! Clearly, I've just started learning this language ~20 minutes before I made this post, and am still learning the basics. Do you guys know of any guides for a beginner? I am definitely willing to take the time to learn in depth :)

[toc] | [prev] | [next] | [standalone]


#55102

FromJoel Goldstick <joel.goldstick@gmail.com>
Date2013-09-30 15:02 -0400
Message-ID<mailman.500.1380567748.18130.python-list@python.org>
In reply to#55094

[Multipart message — attachments visible in raw view] — view raw

On Mon, Sep 30, 2013 at 1:50 PM, <vignesh.harikrishna@gmail.com> wrote:

> Thank you both so much! I'll be sure to make more pertinent subject lines
> now :) Thanks for the detailed explanations! Clearly, I've just started
> learning this language ~20 minutes before I made this post, and am still
> learning the basics. Do you guys know of any guides for a beginner? I am
> definitely willing to take the time to learn in depth :)
>

check out the documentation links on python.org to start

> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 
Joel Goldstick
http://joelgoldstick.com

[toc] | [prev] | [next] | [standalone]


#55227

Fromrusi <rustompmody@gmail.com>
Date2013-10-01 10:12 -0700
Message-ID<aae232cc-0d39-4bea-a1c4-ea70badfb180@googlegroups.com>
In reply to#55094
On Monday, September 30, 2013 11:20:16 PM UTC+5:30, vignesh.h...@gmail.com wrote:
> Thank you both so much! I'll be sure to make more pertinent subject lines now :) Thanks for the detailed explanations! Clearly, I've just started learning this language ~20 minutes before I made this post, and am still learning the basics. Do you guys know of any guides for a beginner? I am definitely willing to take the time to learn in depth :)

Have you seen http://docs.python.org/2/tutorial/ ??
Its kind of required reading for beginners.  A little time spent on that will save a lot on head-scratchers avoided.

After that there are the language and the library references
http://docs.python.org/2/reference/index.html#reference-index
http://docs.python.org/2/library/index.html#library-index

The library is ok if you stick to modules that make sense to you.
The language-ref is too heavy-going for a beginner -- other material/books may be preferable.

[toc] | [prev] | [next] | [standalone]


#55228

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2013-10-01 18:25 +0100
Message-ID<mailman.565.1380648324.18130.python-list@python.org>
In reply to#55094
On 30/09/2013 18:50, vignesh.harikrishna@gmail.com wrote:
> Thank you both so much! I'll be sure to make more pertinent subject lines now :) Thanks for the detailed explanations! Clearly, I've just started learning this language ~20 minutes before I made this post, and am still learning the basics. Do you guys know of any guides for a beginner? I am definitely willing to take the time to learn in depth :)
>

As a newbie you might like to try the tutor mailing list see 
https://mail.python.org/mailman/listinfo/tutor

-- 
Cheers.

Mark Lawrence

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web