通过有道词典进行翻译
import json
import requests
from tkinter import *
word=input()
data = {
“i”: word,
“from”: “AUTO”,
“to”: “AUTO”,
“smartresult”: “dict”,
“client”: “fanyideskweb”,
“doctype”: “json”,
“version”: “2.1”,
“keyfrom”: “fanyi.web”,
“action”: “FY_BY_REALTIME”,
“typoResult”: “true”
}
url = “http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule”
res = requests.post(url, data=data)
js = res.json()
if(js[‘type’]==‘UNSUPPORTED’):
print(“你的输入为空”)
elif(js[‘translateResult’][0][0][‘src’]==js[‘translateResult’][0][0][‘tgt’]):
print(‘你输入错误’)
else:
print(js[‘translateResult’][0][0][‘tgt’])
通过CSV进行猜单词游戏
from random import shuffle
import random
import csv
filename=‘English.csv’
with open(filename) as f:
reader= csv.reader(f)
reader_list=list(reader)
print(reader_list)
print(reader_list[1])
flag1=random.randint(0,len(reader_list)-1)
flag2=random.randint(0,len(reader_list[flag1])-1)
s=reader_list[flag1][flag2]
result=random.sample(s,len(s))
print("长度 ",len(s))
result=’’.join(result)
print(result)
print(“请输入正确单词”);
sum=1;
while True:
m=input();
if(m==s):
print(“输入正确\n”);
break;
else:
print(“输入错误\n”);
sum=sum+1;
print(“你的正确率是: \n”,1/sum*100,"%")