Mayuresh Marathe wrote: > Dear Sir, > > > > I would request kind help in sorting a problem out as I am getting improper > results. I am pasting the program and its output for reference. > > > > Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit > (Intel)] on win32 > > Type "copyright", "credits" or "license()" for more information. > > >>> print ("Please give a number: ") > > Please give a number: > > >>> a = input() > > 12 > > >>> Print ("And another :") > > Traceback (most recent call last): > > File "<pyshell#2>", line 1, in <module> > > Print ("And another :") > > NameError: name 'Print' is not defined > > >>> print ("And another: ") > > And another: > > >>> b = input() > > 23 > > >>> print ("The sum of these numbers is :") > > The sum of these numbers is : > > >>> print (a+b) > > 1223 > > >>> print a+b > > SyntaxError: invalid syntax (<pyshell#7>, line 1) > > >>> print("a+b") > > a+b > > >>> print (a+b) > > 1223 > > >>> >
Hello Mayuresh, In version 3.0 and above of Python, the input() function always returns a string. To get what you want, pass the strings returned by input() into the int() function in order to convert them to integers, for example: >>> a = int(input()) In your above example, both 'a' and 'b' are variables referring to strings, not numbers. In Python, "adding" strings means concatenation, for example "abc" + "ecf" will become the string "abcdef", and similarly "12" + "23" becomes "1223". On the other hand, 12 + 23 becomes 35, since 12 and 23 are integers (whole numbers). It is useful to just write the name of a variable and then enter in the shell, which prints that variable's representation. For example: >>> a = "12" >>> b = 12 >>> a '12' >>> b 12 >From the output above you can see that the variable 'a' refers to a string, while the variable 'b' refers to an integer. Finally, this mailing list is for the discussion of IDLE itself. While I'm happy to help, general Python questions such as this are better directed to other places, where you will get more answer more quickly. See http://wiki.python.org/moin/BeginnersGuide, and specifically http://wiki.python.org/moin/BeginnersGuide/Help, for details on good places to get help for beginning with Python. I highly recommend posting on the comp.lang.python newsgroup, and searching there since answers to most Python questions are already there! Good luck! - Tal
_______________________________________________ IDLE-dev mailing list IDLE-dev@python.org http://mail.python.org/mailman/listinfo/idle-dev