请帮忙,在一个文件中,我有一个函数 initialize,其中包含一个数据对象数组。当用户输入 mediaitem 的参考号时,如何制作一个可以删除 mediaitem 的函数?另外,如何根据用户输入的内容添加媒体创意?
我需要添加/删除项目的功能是:
def initialize():
medialist=[
MediaItem("TU2RL012","Movie","2001: A Space Odyssey",11.99, None ,"Stanley Kubrick","Keir Dullea"),
MediaItem("GV5N32M9","Book","A Brief History of Time",10.17,"Stephen Hawking", None, None),
MediaItem("1DB6HK3L","Movie","North by Northwest",8.99, None, "Alfred Hitchcock","Cary Grant"),
MediaItem("PO5T7Y89","Movie", "The Good, The Bad, The Ugly",9.99,None,"Sergio Leone", "Clint Eastwood"),
MediaItem("TR3FL0EW","Book","The Alchemist",6.99,"Paulo Coelho", None,None),
MediaItem("F2O9PIE9", "Book", "Thus Spoke Zarathustra",7.81, "Friedrich Nietzsche", None, None),
MediaItem("R399CED1","Book", "Jonathan Living Seagull",6.97,"Richard Bach", None, None),
MediaItem("2FG6B2N9","Movie", "Gone with the Wind",4.99, "Victor Fleming","Vivien Leigh", None),
MediaItem("6Y9OPL87","Book", "Gone with the Wind",7.99, "Margarett Mitchell", None, None)
]
return medialist
要添加一个项目,这是我迄今为止编码的内容:
def create_item():
x=input("Book or Movie?")
for obj in initialize():
if x== "Movie":
obj.media="Movie"
obj.title=input("Enter Movie Title:")
obj.reference=input("Enter Movie Reference:")
obj.price=input("Enter Movie Price:")
obj.director=input("Enter Director Name:")
obj.lead_actor=input("Enter Lead Actor Name:")
break
if x== "Book":
obj.media="Book"
obj.title=input("Enter Book Title:")
obj.reference=input("Enter Book Reference:")
obj.price=input("Enter Book Price:")
obj.author=input("Enter Author Name:")
break
else:
print("Wrong Input!")
千万里不及你
慕桂英546537
蛊毒传说
相关分类