栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

单词记忆系统一:菜单循环和菜单确认(Python 自定义类、自定义模块的相对路径import)

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

单词记忆系统一:菜单循环和菜单确认(Python 自定义类、自定义模块的相对路径import)


Python 官网: python 前沿。可惜是英文原版。所以,我要练习英文阅读。類類" rel="noopener noreferrer">https://www.python.org/


  • Free:大咖免费“圣经”教程《 python 完全自学教程》,不仅仅是基础那么简单……

  • My CSDN主页、My HOT博、My Python 学习个人备忘录
  • 好文力荐、 老齐教室

  自学并不是什么神秘的东西,一个人一辈子自学的时间总是比在学校学习的时间长,没有老师的时候总是比有老师的时候多。
            —— 华罗庚





单词记忆系统一:
菜单循环和菜单确认
(Python 自定义类、自定义模块的相对路径import)




        目录


    1、本练习缘来     2、“框架”构想     3、系统主菜单     4、菜单确认
回首页

本练习缘来

  想写这个“单词记忆系统”,是缘于看到有人想用“网”到的代码(点击蓝色文字查看那段代码)给孩子做一个“单词记忆”程序。仔细研读那段代码,感觉不是我想要的那种,决定给自己“鼓捣”一个“真正”的“单词记忆系统”,至少要让单词库得以在磁盘文件保存保存,才算得上勉强可用的“系统”。


“框架”构想

  我现在正在学习python class 和 python 的包、模块的 import ,正好在做这个“单词记忆系统”时炼炼。
  虽然代码有些丑,但终究还是通过了调试,达成目的。浪浪



系统目录结构



系统主程序代码

#!/sur/bin/nve python 
# coding: utf-8 

'''

filename: word_remember.py

author: 梦幻精灵_cq

time: 2022-6-19 10:31am

'''

from word_remember_tools import menu_show, ismenu
from mypytools.python_color import color

menu_str = '单词练习,单词测试,生词添加,系统文档'.split(',')

while True:
    menu_show.MenuShow().show(menu_str) # 调用模块列印菜单。
    try:
        menu_choice = int(input(f"{'-'*50}nn{'':>12}{color('选择菜单', 'f_green')}:"))
    except Exception as error:
        input(f"nn{'-'*50}n{color('选择错误!'.center(45, '-'),'f_red')}n{color('ErrorType:', 'f_gray')} {color(error, 'f_red')}n{'-'*50}nn")
        continue
    if menu_choice not in range(len(menu_str)+1):
        input(f"nn{'-'*50}n{color('选择错误!'.center(45, '-'),'f_red')}n{'-'*50}nn")
        continue
    if not ismenu.IsMenu().ismenu(menu_choice):
        break # 菜单选择0,退出系统菜单循环。


回首页

系统主菜单


1. 菜单列印代码

#!/sur/bin/nve python 
# coding: utf-8 

'''

filename = 'word_remember_tools/menu_show.py'

author = 'Dream_elf'

time = '2022-06-19'

'''


from mypytools.mypythontools import localtime_show # 加载时间字符格式化字符串获取工具。
from mypytools.python_color import color # 加载打印色彩控制工具。
from os import system # 加载命令执行“容器”。

# 菜单列印模块。

class MenuShow:


    def show(self, menu_str):
        '''
        菜单列印。
        遍历菜单列表打印菜单。
        
        '''
        system('clear')
        print(f"nn{'*'*50}nn{'单词记忆系统'.center(44)}n{color('(Word Remember)','f_green').center(59)}nn{localtime_show().center(61)}n{'-'*50}")
        for k,i in enumerate(menu_str):
            print(f"n{'':>20}{k+1}. {color(i, 'f_green')}")
        print(f"n{'':>20}0. {color('退出系统','f_gray')}")

2. 菜单列印效果


回首页

菜单确认代码

#!/sur/bin/nve python 
# coding: utf-8 

'''

filename = 'word_remember_tools/ismenu.py'

author = 'Dream_elf'

time = '2022-06-19'

'''

from mypytools.python_color import color # 加载打印色彩控制工具。
from os import system # 加载命令执行“容器”。


class IsMenu:
    
    
    def ismenu(self, menu_choice):
        '''
        菜单选择确认,根据所选序号,
        调用相应功能模块。
        '''
        num = menu_choice # 菜单选择变量别名。
        if not num: # 退出系统。
            print(f"nn{'-'*50}n{color('正在保存词库……','f_green').center(51)}n{'-'*50}")
            pass # 词库保存,程序设计中。
            system('clear')
            print(f"nn{color('-'*50, 'f_green')}nn{color('谢谢使用“单词记忆系统”!','f_yellow').center(48)}nn{color('Author: Dream Elf','f_gray').center(56)}n{color('*'*50,'f_green')}nn")
            return num
        elif num == 1: # 单词练习。
            input(f"nn{'-'*50}n{color('单词练习正在建设……','f_green').center(49)}n{'-'*50}")
            return num
        elif num == 2: # 单词测试。
            input(f"nn{'-'*50}n{color('单词测试正在建设……','f_green').center(49)}n{'-'*50}")
            return num
        elif num == 3: # 生词添加。
            input(f"nn{'-'*50}n{color('生词添加正在建设……','f_green').center(49)}n{'-'*50}")
            return num
        elif num == 4: # 说明文档。
            input(f"nn{'-'*50}n{color('说明文档正在建设……','f_green').center(49)}n{'-'*50}")
            return num 

菜单选择错误提示


1. 输入错误



2. 超出范围



优化了“菜单选择”错误提示字符串列印格式:

1. 代码

from word_remember_tools import menu_show, ismenu
from mypytools.python_color import color

menu_str = '单词练习,单词测试,生词添加,系统文档'.split(',') # 系统菜单字符串列表。

while True:
    menu_show.MenuShow().show(menu_str) # 调用模块列印菜单。
    try:
        menu_choice = int(input(f"{'-'*50}nn{'':>12}{color('选择菜单', 'f_green')}:"))
    except Exception as error:
        input(f"nn{'-'*50}nn{color(' 选择错误!'.center(45, '-'),'f_red')}nn{color('ErrorType:', 'f_gray')} {color(error, 'f_yellow')}n{'-'*50}nn")
        continue
    if menu_choice not in range(len(menu_str)+1):
        error = f"您输入的数字,超出菜单序号选择范围 '1~{len(menu_str)}' :'{menu_choice}' "
        input(f"nn{'-'*50}nn{color('选择错误!'.center(45, '-'),'f_red')}nn{color('错误类型:', 'f_gray')}{color(error, 'f_yellow')}n{'-'*50}nn")
        continue
    if not ismenu.IsMenu().ismenu(menu_choice):
        break # 菜单选择0,退出系统菜单循环。

2. 效果



(2022-06-20 06:29 am)


菜单确认之“系统退出”提示


回目录


别人“网”来,准备给孩子做“单词记忆”程序的代码:

import random
import turtle as t

WORDS = {"easy": "简单", "difficult": "困难", "answer": "答案"}

iscontinue = "y"
while iscontinue == "y" or iscontinue == "Y":

      print(
          """
                          欢迎使用BillChen单词速背系统 
             英译汉请输入Y    汉译英请输入N   添加单词请按L
             模拟练习请按T    结束程序请按W   开发详情请按任意键
"""
      )
      F = input()
      if F == 'N' or F == 'n':
            new_WORDS = {v: k for k, v in WORDS.items()}
            n = input("请输入需要查询的单词或词语:")
            if n in new_WORDS:
                  print(new_WORDS[n])
            else:
                  print('暂未收录,敬请期待')
            iscontinue = input("nn是否继续(Y/N):")
      elif F == 'Y' or F == 'y':
            n = input("请输入需要查询的单词或词语:")
            if n in WORDS:
                  print(WORDS[n])
            else:
                  print('暂未收录,敬请期待')
            iscontinue = input("nn是否继续(Y/N):")
      elif F == 'L' or F == 'l':
            new_value = input('请输入一个新的单词的释义:')
            new_key = input('请输入这个新单词:')
            WORDS[new_key] = new_value
            print(WORDS)
      elif F == 'T' or F == 't':
            i = 0
            z = 0
            while i < 5:

                  key = random.choice(list(WORDS))
                  right_key = WORDS[key]
                  print(key)
                  user_key = input("请输入这个单词的释义:")
                  if user_key == right_key:
                        print('恭喜您,此题答对了')

                        z = z + 1

                  else:
                        print('很遗憾,此题打错了,再接再厉哦')
                        print('正确答案是:{}'.format(right_key))
                        '''
                                       2021/2/7根据树扇风吹云起的提议增添答错时会输出正确答案
                                    '''

                  i = i + 1

            print('恭喜您,本次模拟结束,本次您的正确率为:{:.2%}'.format(z / 5))
      elif F == 'W' or F == 'w':
            print("程序已经退出,欢迎您的下次使用")
            iscontinue = "n"
      else:
            t.setup(1800, 800, 0, 0)
            t.bgcolor('pink')
            t.color('red')
            t.shape('turtle')
            t.speed(5)
            t.begin_fill()
            t.up()
            t.goto(-120, 100)
            t.down()
            for i in range(5):
                  t.forward(240)
                  t.right(144)
            t.end_fill()
            t.penup()
            t.goto(200, 100)
            t.pendown
            t.color('black')
            t.write('开发人员:popolo', font=("Arial", 34, "normal"))
            t.right(90)
            t.fd(100)
            t.color('red')
            t.write('♥', font=("Arial", 34, "italic"))
            t.left(90)
            t.fd(50)
            t.color('black')
            t.write('学号:201805050118', font=("Arial", 34, "italic"))
            t.right(90)
            t.fd(100)
            t.write('班级:18计科本1班', font=("Arial", 34, "bold"))
            t.right(90)
            t.fd(500)
            t.write('考试必过', font=("Arial", 34, "bold"))
            t.right(90)
            t.fd(300)
            t.write('单词速背系统', font=("Arial", 34, "bold"))
            t.hideturtle()
            t.exitonclick()

回首页


My Up and Down: __上一篇:__ 练习:数字时钟(Python 自定义类)

__下一篇:__ 仿真模拟双色球

我的HOT博:
  • 练习:银行复利计算(用 for 循环解一道初中小题)(1040阅读)
  • pandas 数据类型之 DataFrame(1238阅读)
  • 班里有人和我同生日难吗?(概率probability、蒙特卡洛随机模拟法)(2067阅读)
  • Python字符串居中显示(1402阅读)
  • 练习:求偶数和、阈值分割和求差( list 对象的两个基础小题)(1633阅读)
  • 用 pandas 解一道小题(1954阅读)
  • 可迭代对象和四个函数(1061阅读)
  • “快乐数”判断(1224阅读)
  • 罗马数字转换器(构造元素取模)(1923阅读)
  • Hot:罗马数字(转换器|罗生成器)(3405阅读)
  • Hot:让QQ群昵称色变的代码(25245阅读)
  • Hot:斐波那契数列(递归| for )(3946阅读)
  • 柱状图中最大矩形(1639阅读)
  • 排序数组元素的重复起止(1230阅读)
  • 电话拨号键盘字母组合(1335阅读)
  • 密码强度检测器(1782阅读)
  • 求列表平衡点(1804阅读)
  • Hot: 字符串统计(4193阅读)
  • Hot:尼姆游戏(聪明版首发)(3405阅读)尼姆游戏(优化版)(975阅读)
推荐条件 点阅破千

回目录


精品文章:
  • 好文力荐:《python 完全自学教程》齐伟书稿免费连载
  • OPP三大特性:封装中的property
  • 通过内置对象理解python'
  • 正则表达式
  • python中“*”的作用
  • Python 完全自学手册
  • 海象运算符
  • Python中的 `!=`与`is not`不同
  • 学习编程的正确方法

来源:老齐教室


回目录

Python 入门指南【Python 3.6.3】
好文力荐:
  • 全栈领域优质创作者——寒佬(还是国内某高校学生)好文:《非技术文—关于英语和如何正确的提问》,“英语”和“会提问”是学习的两大利器。

  • 【8大编程语言的适用领域】先别着急选语言学编程,先看它们能干嘛

  • 靠谱程序员的好习惯


CSDN实用技巧博文:
  • 8个好用到爆的Python实用技巧
  • python忽略警告

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/983744.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号