<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jun 2, 2013 at 6:12 PM, Fdama <span dir="ltr"><<a href="mailto:fsdama@gmail.com" target="_blank">fsdama@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
<br>
I was following an exercise in a book when I edited the code and came across something I did not get. Here is the relevant part of the code that works:<br>
<br>
start=None      #initialise<br>
while start !="":<br>
    start=input("\nStart: ")<br>
<br>
    if start:<br>
        start=int(start)<br>
        finish=int(input("Finish: "))<br>
<br>
        print("word[",start,":",finish,"] is", word[start:finish])<br>
<br>
I then changed the code to this:<br>
<br>
start=None      #initialise<br>
while start !="":<br>
    start=int(input("\nStart: "))<br>
<br>
    if start:<br>
<br>
        finish=int(input("Finish: "))<br>
<br>
        print("word[",start,":",finish,"] is", word[start:finish])<br>
<br>
I combined the int conversion and the input on the same line, rather than to have two different statements. But  got an error message:<br>
<br>
Traceback (most recent call last):<br>
  File "C:\Users\Faisal\Documents\python\pizza_slicer.py", line 23, in <module><br>
    start=int(input("\nStart: "))<br>
ValueError: invalid literal for int() with base 10: ''<span class="HOEnZb"><font color="#888888"><br></font></span></blockquote><div><br></div><div>Converting an empty string to base 10 doesn't fly, so if you hit a blank line on the input(), you get a bad conversion.  In the first version, you're only converting to base 10 if the string is non-empty.  In the second, you're attempting to convert irrespective.<br>
<br></div><div>BTW, I'm partial to:<br><br></div><div>if not start:<br></div><div>   continue<br><br></div><div>...but that's a stylistic thing.<br><br></div></div></div></div>