<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: &quot;Courier New&quot;;">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: &quot;Courier New&quot;;">Type &quot;copyright&quot;,
&quot;credits&quot; or &quot;license()&quot; for more information.</span></font></p>

<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;">&gt;&gt;&gt; print
(&quot;Please give a number: &quot;)</span></font></p>

<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;">Please give a number: </span></font></p>

<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;">&gt;&gt;&gt; a = input()</span></font></p>

<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;">12</span></font></p>

<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;">&gt;&gt;&gt; Print
(&quot;And another :&quot;)</span></font></p>

<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;">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: &quot;Courier New&quot;;">  File
&quot;&lt;pyshell#2&gt;&quot;, line 1, in &lt;module&gt;</span></font></p>

<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;">    Print (&quot;And another
:&quot;)</span></font></p>

<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;">NameError: name &#39;Print&#39; is
not defined</span></font></p>

<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;">&gt;&gt;&gt; print
(&quot;And another: &quot;)</span></font></p>

<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;">And another: </span></font></p>

<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;">&gt;&gt;&gt; b = input()</span></font></p>

<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;">23</span></font></p>

<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;">&gt;&gt;&gt; print
(&quot;The sum of these numbers is :&quot;)</span></font></p>

<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;">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: &quot;Courier New&quot;;">&gt;&gt;&gt; print (a+b)</span></font></p>

<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;">1223</span></font></p>

<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;">&gt;&gt;&gt; print a+b</span></font></p>

<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;">SyntaxError: invalid syntax
(&lt;pyshell#7&gt;, line 1)</span></font></p>

<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;">&gt;&gt;&gt;
print(&quot;a+b&quot;)</span></font></p>

<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;">a+b</span></font></p>

<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;">&gt;&gt;&gt; print (a+b)</span></font></p>

<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;">1223</span></font></p>

<p class="MsoNormal" style=""><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;">&gt;&gt;&gt; </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>
&gt;&gt;&gt; a = int(input())<br><br>In your above example, both &#39;a&#39; and &#39;b&#39; are variables referring to strings, not numbers. In Python, &quot;adding&quot; strings means concatenation, for example &quot;abc&quot; + &quot;ecf&quot; will become the string &quot;abcdef&quot;, and similarly &quot;12&quot; + &quot;23&quot; becomes &quot;1223&quot;. 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&#39;s representation. For example:<br><br>&gt;&gt;&gt; a = &quot;12&quot;<br>&gt;&gt;&gt; b = 12<br>&gt;&gt;&gt; a<br>

&#39;12&#39;<br>&gt;&gt;&gt; b<br>12<br><br>From the output above you can see that the variable &#39;a&#39; refers to a string, while the variable &#39;b&#39; refers to an integer.<br><br><br>Finally, this mailing list is for the discussion of IDLE itself. While I&#39;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>