程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Word memory system I: menu cycle and menu confirmation (relative path of Python custom class and custom module import)

編輯:Python

Python Official website python the front . Unfortunately, it's the original English version . therefore , I want to practice English reading .🧐🧐" rel="noopener noreferrer">https://www.python.org/


  • Free: Big coffee free “ Bible ” course 《 python Complete self study course 》, It's not just the basics ……

  • My CSDN Home page 、My HOT Bo 、My Python Study personal memos
  • A good writer recommends 、 Laoqi classroom

Self study is not a mysterious thing , A person's self-study time is always longer than that in school , There are always more times when there are no teachers than when there are teachers .
—— Hua Luogeng





Word memory system one :
Menu cycle and menu confirmation
(Python Custom class 、 Relative path of custom module import)




Catalog


1、 This exercise comes from

2、“ frame ” concept

3、 System main menu

4、 Menu confirmation


Home

This exercise comes from

Want to write this “ Word memory system ”, It's because I see someone who wants to use “ network ” Code to ( Click on the blue text to view the code ) Make a... For the child “ Word memory ” Program . Read that code carefully , It doesn't feel like what I want , Decide to give yourself “ Agitate ” One “ real ” Of “ Word memory system ”, At least let the word library be saved in a disk file , Can be considered as barely usable “ System ”.


“ frame ” concept

I'm studying now python class and python My bag 、 Modular import , Just doing this “ Word memory system ” Time refining .
Although the code is a bit ugly , But it passed the debugging after all , To achieve an end .🤪🤪



System directory structure



System main program code

#!/sur/bin/nve python 
# coding: utf-8 
''' filename: word_remember.py author: The dream spirit _cq time: 2022-6-19 10:31am '''
from word_remember_tools import menu_show, ismenu
from mypytools.python_color import color
menu_str = ' Word practice , Word test , Add new words , System documentation '.split(',')
while True:
menu_show.MenuShow().show(menu_str) # Call the module print menu .
try:
menu_choice = int(input(f"{
'-'*50}\n\n{
'':>12}{
color(' Menu selection ', 'f_green')}:"))
except Exception as error:
input(f"\n\n{
'-'*50}\n{
color(' Wrong choice !'.center(45, '-'),'f_red')}\n{
color('ErrorType:', 'f_gray')} {
color(error, 'f_red')}\n{
'-'*50}\n\n")
continue
if menu_choice not in range(len(menu_str)+1):
input(f"\n\n{
'-'*50}\n{
color(' Wrong choice !'.center(45, '-'),'f_red')}\n{
'-'*50}\n\n")
continue
if not ismenu.IsMenu().ismenu(menu_choice):
break # Menu selection 0, Exit the system menu cycle .

Home

System main menu


1. Menu print code

#!/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 # Load the time character format string acquisition tool .
from mypytools.python_color import color # Load the print color control tool .
from os import system # Load command execution “ Containers ”.
# Menu printing module .
class MenuShow:
def show(self, menu_str):
''' Menu printing . Traverse the menu list and print the menu . '''
system('clear')
print(f"\n\n{
'*'*50}\n\n{
' Word memory system '.center(44)}\n{
color('(Word Remember)','f_green').center(59)}\n\n{
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(' Exit the system ','f_gray')}")

2. Menu printing effect


Home

Menu confirmation code

#!/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 # Load the print color control tool .
from os import system # Load command execution “ Containers ”.
class IsMenu:
def ismenu(self, menu_choice):
''' Menu select OK , According to the selected sequence number , Call the corresponding function module . '''
num = menu_choice # Select variable alias from the menu .
if not num: # Exit the system .
print(f"\n\n{
'-'*50}\n{
color(' Saving Thesaurus ……','f_green').center(51)}\n{
'-'*50}")
pass # Thesaurus save , In programming .
system('clear')
print(f"\n\n{
color('-'*50, 'f_green')}\n\n{
color(' Thank you for using. “ Word memory system ”!','f_yellow').center(48)}\n\n{
color('Author: Dream Elf','f_gray').center(56)}\n{
color('*'*50,'f_green')}\n\n")
return num
elif num == 1: # Word practice .
input(f"\n\n{
'-'*50}\n{
color(' Word practice is under construction ……','f_green').center(49)}\n{
'-'*50}")
return num
elif num == 2: # Word test .
input(f"\n\n{
'-'*50}\n{
color(' The word test is under construction ……','f_green').center(49)}\n{
'-'*50}")
return num
elif num == 3: # Add new words .
input(f"\n\n{
'-'*50}\n{
color(' Adding new words is under construction ……','f_green').center(49)}\n{
'-'*50}")
return num
elif num == 4: # documentation .
input(f"\n\n{
'-'*50}\n{
color(' The documentation is under construction ……','f_green').center(49)}\n{
'-'*50}")
return num

Menu selection error prompt


1. Input error



2. Out of range



To optimize the “ Menu selection ” Error message String printing format :

1. Code

from word_remember_tools import menu_show, ismenu
from mypytools.python_color import color
menu_str = ' Word practice , Word test , Add new words , System documentation '.split(',') # System menu string list .
while True:
menu_show.MenuShow().show(menu_str) # Call the module print menu .
try:
menu_choice = int(input(f"{
'-'*50}\n\n{
'':>12}{
color(' Menu selection ', 'f_green')}:"))
except Exception as error:
input(f"\n\n{
'-'*50}\n\n{
color(' Wrong choice !'.center(45, '-'),'f_red')}\n\n{
color('ErrorType:', 'f_gray')} {
color(error, 'f_yellow')}\n{
'-'*50}\n\n")
continue
if menu_choice not in range(len(menu_str)+1):
error = f" The number you entered , Out of menu sequence number selection range '1~{
len(menu_str)}' :'{
menu_choice}' "
input(f"\n\n{
'-'*50}\n\n{
color(' Wrong choice !'.center(45, '-'),'f_red')}\n\n{
color(' Wrong type :', 'f_gray')}{
color(error, 'f_yellow')}\n{
'-'*50}\n\n")
continue
if not ismenu.IsMenu().ismenu(menu_choice):
break # Menu selection 0, Exit the system menu cycle .

2. effect



(2022-06-20 06:29 am)


Menu confirmation “ System exit ” Tips


Go back to the catalog


others “ network ” Come on , Prepare for the children “ Word memory ” The code of the program :

import random
import turtle as t
WORDS = {
"easy": " Simple ", "difficult": " difficult ", "answer": " answer "}
iscontinue = "y"
while iscontinue == "y" or iscontinue == "Y":
print(
""" Welcome to use BillChen Word speed back system Please enter Y Please enter N To add a word, press L For simulation exercise, please press T To end the program, press W For development details, please press any key """
)
F = input()
if F == 'N' or F == 'n':
new_WORDS = {
v: k for k, v in WORDS.items()}
n = input(" Please enter the word or words to query :")
if n in new_WORDS:
print(new_WORDS[n])
else:
print(' Not included yet , Coming soon ')
iscontinue = input("\n\n Whether or not to continue (Y/N):")
elif F == 'Y' or F == 'y':
n = input(" Please enter the word or words to query :")
if n in WORDS:
print(WORDS[n])
else:
print(' Not included yet , Coming soon ')
iscontinue = input("\n\n Whether or not to continue (Y/N):")
elif F == 'L' or F == 'l':
new_value = input(' Please enter the definition of a new word :')
new_key = input(' Please enter this new word :')
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(" Please enter the definition of this word :")
if user_key == right_key:
print(' Congratulations , The answer to this question is correct ')
z = z + 1
else:
print(' unfortunately , This question is wrong , Keep up your efforts ')
print(' The right answer is :{}'.format(right_key))
''' 2021/2/7 According to the proposal of tree fan blowing clouds, the correct answer will be output when the answer is wrong '''
i = i + 1
print(' Congratulations , The simulation is over , Your accuracy rate this time is :{:.2%}'.format(z / 5))
elif F == 'W' or F == 'w':
print(" Program has exited , Welcome to your next use ")
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(' Developer :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(' Student number :201805050118', font=("Arial", 34, "italic"))
t.right(90)
t.fd(100)
t.write(' class :18 Ji Keben 1 class ', font=("Arial", 34, "bold"))
t.right(90)
t.fd(500)
t.write(' You must pass the exam ', font=("Arial", 34, "bold"))
t.right(90)
t.fd(300)
t.write(' Word speed back system ', font=("Arial", 34, "bold"))
t.hideturtle()
t.exitonclick()

Home


My Up and Down

__ Last one :__ practice : Digital clock (Python Custom class )

__ Next :__ Simulation simulation of two-color ball

my HOT Bo :

  • practice : Calculation of bank compound interest ( use for Solve a junior high school problem in a circular way )(1040 read )
  • pandas Data type DataFrame(1238 read )
  • Is it difficult for someone in the class to have the same birthday as me ?( probability probability、 Monte Carlo stochastic simulation method )(2067 read )
  • Python The string is centered (1402 read )
  • practice : Even sum 、 Threshold segmentation and subtraction ( list Two basic questions of the object )(1633 read )
  • use pandas Solve a small problem (1954 read )
  • Iteratable object and four functions (1061 read )
  • “ Happy number ” Judge (1224 read )
  • Roman digital converter ( Construct element module )(1923 read )
  • Hot: Rome digital ( converter | Luo )(3405 read )
  • Hot: Give Way QQ Group nickname color change code (25245 read )
  • Hot: Fibonacci sequence ( recursive | for )(3946 read )
  • The largest rectangle in the histogram (1639 read )
  • Repeat start and end of sorting array elements (1230 read )
  • Telephone dialing keyboard letter combination (1335 read )
  • Password strength detector (1782 read )
  • Find the balance point of the list (1804 read )
  • Hot: String statistics (4193 read )
  • Hot: Nim game ( Smart version starts )(3405 read ) Nim game ( Optimized version )(975 read )
Recommended conditions Click to read a thousand

Go back to the catalog


Excellent articles :

  • A good writer recommends :《python Complete self study course 》 Qi Wei manuscript free Serial
  • OPP The three major characteristics : In the package property
  • Understand through built-in objects python'
  • Regular expressions
  • python in “*” The role of
  • Python A complete self-study manual
  • Walrus operators
  • Python Medium `!=` And `is not` Different
  • The right way to learn programming

source : Laoqi classroom


Go back to the catalog

Python Getting started 【Python 3.6.3】


A good writer recommends :

  • High quality creators in the whole stack field —— Cold guy ( Or a domestic college student ) Good writing :《 Non technical paper — About English and how to ask questions correctly 》,“ English ” and “ I will ask questions ” Are two sharp tools for learning .

  • 【8 Application fields of large programming languages 】 Don't worry about choosing Linguistic Programming , Let's see what they can do first

  • Good habits of reliable programmers


CSDN Practical skills blog :

  • 8 A good one Python Practical skills
  • python Ignore the warning


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved