一節(jié)普通的信息課(2023.03.24)
friends = ['張三','李四','王五']
print("這是普通軟件的好友管理系統(tǒng)")
print("1: 添加好友")
print("2: 刪除好友")
print("3: 備注好友")
print("4: 展示好友")
print("5: 退出")
while True:
? ?num = input("請輸入你要實(shí)現(xiàn)的功能: ") #避免了輸入非數(shù)字時(shí)報(bào)錯(cuò)
? ?if num == '1': #呼應(yīng)上文,使用字符來判斷
? ? ? ?add_friend = input("請輸入要添加的好友: ")
? ? ? ?friends.append(add_friend)
? ? ? ?print("好友添加成功")
? ?elif num == '2':
? ? ? ?del_friend = input("請輸入要?jiǎng)h除的好友: ")
? ? ? ?friends.remove(del_friend)
? ? ? ?print("好友刪除成功")
? ?elif num == '3':
? ? ? ?pas_friend = input("請輸入要修改的好友姓名: ")
? ? ? ?now_friend = input("請輸入修改后的好友姓名: ")
? ? ? ?friend_index = friend.index(pas_friend)
? ? ? ?friends[friend_index] = now_friend
? ? ? ?print("修改成功")
? ?elif num == '4':
? ? ? ?if len(friends) == 0:
? ? ? ? ? ?print("改悔罷!你并無好友")
? ? ? ?else:
? ? ? ? ? ?for i in friends:
? ? ? ? ? ? ? ?print(i)
? ?elif num == '5':
? ? ? ?break
? ?else:
? ? ? ?print(num,",請注意看提示")