[Tutor] if statement

bob gailer bgailer at gmail.com
Tue Nov 2 22:18:17 CET 2010


On 11/2/2010 3:07 PM, Glen Clark wrote:
> sorry:
>
> NumItems = int(input("How many Items: "))
>
>
> Entries = []
> for In in range(0,NumItems):
>     Entries.append("")
>     	
>
>
> for In in range(0,NumItems):
>     Entries[In]=str(input("Enter name " + str(In+1) + ": "))
>
>
> for In in range(0,NumItems):
>     print(Entries[In])
>
> confirmed = int(input("Are you happy with this? (y/n): ")
>
In addition to the other help - do not use int here. You will get a run 
time error when it tries to convert y or n to an integer. If that 
succeeded e.g. the user entered 3), then confirmed (an integer) will 
NEVER be == "y" (a string).
> if confirmed == "y":
>     for In in range(0,NumItems):
>        print(Entries[In] + ": " + str(In))
>     change = int(input("Which item would you like to change: ")
>     Entries[change]=str(input("Please enter a nem name: ")
> else:
>      #do nothing
>
> print(Entries)
>
> On Tue, 2010-11-02 at 15:05 -0400, Alex Hall wrote:
>> On 11/2/10, Glen Clark<glenuk at gmail.com>  wrote:
>>>   File "/home/glen/workspace/test.py", line 19
>>>      if confirmed == "y":
>>>                         ^
>>> SyntaxError: invalid syntax
>>>
>>> Why does this not work??? PyDev says "Expected:else"
>> It may help to see the rest of the file, or at least more of the code
>> surrounding this statement.
>>> _______________________________________________
>>> Tutor maillist  -  Tutor at python.org
>>> To unsubscribe or change subscription options:
>>> http://mail.python.org/mailman/listinfo/tutor
>>>
>>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>


-- 
Bob Gailer
919-636-4239
Chapel Hill NC



More information about the Tutor mailing list