初级python代码编程学习---- 简单记事本小程序

      简单记事本小程序       

提供一个基于Python的简单记事本小程序示例。这个小程序将允许用户添加、查看和删除记事条。

# Simple Note Pad Mini-Application

# 记事本数据结构
notes = []

def add_note(note):
    """添加一条新的记事条"""
    notes.append(note)
    print("记事条添加成功。")

def show_notes():
    """显示所有记事条"""
    if notes:
        print("您的记事条:")
        for note in notes:
            print(f"- {note}")
    else:
        print("目前没有记事条。")

def delete_note(note):
    """删除一条记事条"""
    if note in notes:
        notes.remove(note)
        print(f"记事条'{note}'已删除。")
    else:
        print("记事条不在列表中。")

def main():
    while True:
        print("\n简单记事本")
        print("1. 添加记事条")
        print("2. 查看记事条")
        print("3. 删除记事条")
        print("4. 退出")

        choice = input("请选择一个操作(1-4):")

        if choice == '1':
            note = input("请输入您的记事条内容:")
            add_note(note)
        elif choice == '2':
            show_notes()
        elif choice == '3':
            note = input("请输入要删除的记事条内容:")
            delete_note(note)
        elif choice == '4':
            print("感谢使用记事本,再见!")
            break
        else:
            print("无效的输入,请输入1-4之间的数字。")

if __name__ == "__main__":
    main()

 

# Simple Note Pad Mini-Application

# 记事本数据结构
notes = []

def add_note(note):
    """添加一条新的记事条"""
    notes.append(note)
    print("记事条添加成功。")

def show_notes():
    """显示所有记事条"""
    if notes:
        print("您的记事条:")
        for note in notes:
            print(f"- {note}")
    else:
        print("目前没有记事条。")

def delete_note(note):
    """删除一条记事条"""
    if note in notes:
        notes.remove(note)
        print(f"记事条'{note}'已删除。")
    else:
        print("记事条不在列表中。")

def main():
    while True:
        print("\n简单记事本")
        print("1. 添加记事条")
        print("2. 查看记事条")
        print("3. 删除记事条")
        print("4. 退出")

        choice = input("请选择一个操作(1-4):")

        if choice == '1':
            note = input("请输入您的记事条内容:")
            add_note(note)
        elif choice == '2':
            show_notes()
        elif choice == '3':
            note = input("请输入要删除的记事条内容:")
            delete_note(note)
        elif choice == '4':
            print("感谢使用记事本,再见!")
            break
        else:
            print("无效的输入,请输入1-4之间的数字。")

if __name__ == "__main__":
    main()

将这段代码保存为.py文件,比如123.py,然后在你的Python环境中运行它。这个小程序将允许你在命令行界面中添加、查看和删除记事条。

在python环境下运行

python 123.py

演示

  • 6
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值