Catalog
One 、 Actual combat scene
Two 、 Main knowledge points
3、 ... and 、 Rookie actual combat
1、 establish python file
2、 File directory
3、 Running results
English Chinese Dictionary : Type in English , Return to corresponding Chinese .
- File read and write
- Basic grammar
- exception handling
- Loop statement
- string manipulation
Make arrangements now !
''' Author: Rookie actual combat Actual combat scene : How to realize an English Chinese translation dictionary ''' # Import system package import platform print("Hello, Rookie actual combat ") print(" Actual combat scene : How to realize an English Chinese translation dictionary ") # English Chinese Dictionary eng_hans_dict = {} with open("py014.txt", encoding="utf8") as fin: # Read the file , Save translation data for line in fin: if len(line.strip()) > 3: eng, hans = line.strip().split(",") eng_hans_dict[eng] = hans print(" English Chinese dictionary data : %s -> %s" % (eng, hans)) def translate(input_word): # translate try: return eng_hans_dict[input_word] except KeyError: return " Words are not in the dictionary " input_word = input(" Please enter the English words to be translated : ").lower() trans_result = translate(input_word) print("%s The result of translation is : %s" % (input_word, trans_result)) print("Python edition ", platform.python_version())
py-014/
├── py014.txt
└── py014.py
Hello, Rookie actual combat
Actual combat scene : How to realize an English Chinese translation dictionary
English Chinese dictionary data : apple -> Apple
English Chinese dictionary data : banana -> Banana
English Chinese dictionary data : blueberry -> blueberries
English Chinese dictionary data : cherry -> Cherry
English Chinese dictionary data : crabapple -> Begonia fruit
English Chinese dictionary data : carambola -> Carambola
English Chinese dictionary data : chestnut -> chestnuts
English Chinese dictionary data : coconut -> Coconut
English Chinese dictionary data : cranberry -> Manyueberry
English Chinese dictionary data : cumquat -> Kumquat
English Chinese dictionary data : orange -> orange
English Chinese dictionary data : pear -> pear
English Chinese dictionary data : peach -> peach
English Chinese dictionary data : grape -> grapes
English Chinese dictionary data : lemon -> lemon
English Chinese dictionary data : lichee -> litchi
English Chinese dictionary data : loquat -> Loquat
English Chinese dictionary data : mango -> Mango.
Please enter the English words to be translated : apple
apple The result of translation is : Apple
Python edition 3.10.4
Rookie actual combat , Continuous learning !
Python3.9.0 for windows- Very
Vue and Django Front and back