Forum Archive

Fixed // Help! Error when removing from list.

Dann239

Works!

Very new to Python... However, I wrote this little list making script.
If I run this, and go to my def Edit(), the script errors out when its asked to remove the item from the list using the user input. If the item in the list is just a single character, it succeeds without error. Any ideas?


import console
list = []

def view():
print("Viewing Data")
sortlist = sorted(list)
print "\n".join(sortlist)
x = raw_input().title()
if x == "Q":
return

def add():
print("In Adding Mode")
sortlist = sorted(list)
print "\n" .join(sortlist)
x = raw_input().title()
if x == "Q":
return
else: list.append(x.title())
console.clear()
add()

def edit():
print("Edit List, Remove?")
sortlist = sorted(list)
print "\n" .join(sortlist)
x = raw_input().title()
if x == "Q":
return
else: list.remove(x)
console.clear()
edit()

while True:
console.clear()
choice = ["[A]dd to list" , "[V]iew List" , "[E]dit List"]
print("List App")
print('\n'.join(choice))
print("Use 'q' to Exit")
x = raw_input().title()
if x == "A":
console.clear()
add()
elif x == "V":
console.clear()
view()
elif x == "E":
console.clear()
edit()

ccc
'THIS' not in ('This', 'Is', 'Text')

Add() calls x.title() but Edit() calls x.upper().

Change all calls to upper() into calls to title() and your script should work.

Also 'while True' is probably easier to understand (and type) than 'while 0 == 0'.

Dann239

I appreciate the help! Thank you.