<div dir="ltr"><div class="gmail_quote">Mayuresh Marathe <span dir="ltr"></span>wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div link="blue" vlink="purple" lang="EN-US">
<div>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">Dear Sir,</span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">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.</span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"> </span></font></p>
<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: "Courier New";">Python 3.1.1 (r311:74483,
Aug 17 2009, 17:02:12) [MSC v.1500 32 bit (Intel)] on win32</span></font></p>
<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: "Courier New";">Type "copyright",
"credits" or "license()" for more information.</span></font></p>
<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: "Courier New";">>>> print
("Please give a number: ")</span></font></p>
<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: "Courier New";">Please give a number: </span></font></p>
<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: "Courier New";">>>> a = input()</span></font></p>
<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: "Courier New";">12</span></font></p>
<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: "Courier New";">>>> Print
("And another :")</span></font></p>
<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: "Courier New";">Traceback (most recent call
last):</span></font></p>
<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: "Courier New";"> File
"<pyshell#2>", line 1, in <module></span></font></p>
<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: "Courier New";"> Print ("And another
:")</span></font></p>
<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: "Courier New";">NameError: name 'Print' is
not defined</span></font></p>
<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: "Courier New";">>>> print
("And another: ")</span></font></p>
<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: "Courier New";">And another: </span></font></p>
<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: "Courier New";">>>> b = input()</span></font></p>
<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: "Courier New";">23</span></font></p>
<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: "Courier New";">>>> print
("The sum of these numbers is :")</span></font></p>
<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: "Courier New";">The sum of these numbers is
:</span></font></p>
<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: "Courier New";">>>> print (a+b)</span></font></p>
<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: "Courier New";">1223</span></font></p>
<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: "Courier New";">>>> print a+b</span></font></p>
<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: "Courier New";">SyntaxError: invalid syntax
(<pyshell#7>, line 1)</span></font></p>
<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: "Courier New";">>>>
print("a+b")</span></font></p>
<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: "Courier New";">a+b</span></font></p>
<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: "Courier New";">>>> print (a+b)</span></font></p>
<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: "Courier New";">1223</span></font></p>
<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: "Courier New";">>>> </span></font></p></div></div></blockquote></div><br>Hello Mayuresh,<br><br>
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: <br>
<br>
>>> a = int(input())<br><br>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).<br>
<br><br>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:<br><br>>>> a = "12"<br>>>> b = 12<br>>>> a<br>
'12'<br>>>> b<br>12<br><br>From the output above you can see that the variable 'a' refers to a string, while the variable 'b' refers to an integer.<br><br><br>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 <a href="http://wiki.python.org/moin/BeginnersGuide">http://wiki.python.org/moin/BeginnersGuide</a>, and specifically <a href="http://wiki.python.org/moin/BeginnersGuide/Help">http://wiki.python.org/moin/BeginnersGuide/Help</a>, 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!<br>
<br><br>Good luck!<br><br>- Tal<br></div>