高分悬赏python问题!好的高分追加!

帮个忙吧,好的话加分,这个程序忙帮做出来吧***PUTYOURALGORITHMHERE***#GivensomewordsineitherEnglishorItalia... 帮个忙吧,好的话加分,这个程序忙帮做出来吧
*** PUT YOUR ALGORITHM HERE ***

# Given some words in either English or Italian convert them to the other language
# Return the converted words.
def translator(language, word):

# create the dictionaries from the given files

# check if the word is in the relevant dictionary

# convert to either Italian or Spanish

# check if translation is same in both Italian and Spanish

# print out a message, e.g.
# The Spanish word for sun is sol
# The Italian word for rubbish is not found
# The Spanish word for great is grande - same in both Italian and Spanish.

# Run the tests if this is the main program:
if __name__ == '__main__':
import doctest
doctest.testmod(verbose=True)

文件: english to spanish
good bueno
afternoon tarde
cat gato
dog perro
white blanco
finish final
exit salida
fever fiebre
fox zorro
jump salto
lazy perezoso
fish pescados
not no
under debajo
pretty bastante
slow lento
sun sol
run funcionamiento
painting pintura
beautiful hermoso
great grande
flower flor
house casa

english to italian
good buono
afternoon pomeriggio
cat gatto
dog cane
white bianco
finish fine
exit uscita
fever febbre
fox volpe
jump salto
lazy pigro
fish pesci
not non
under sotto
pretty carino
slow lento
sun sole
run corsa
painting quandro
beautiful bello
great grande
flower fiore
clever intelligente
house casa

########## END AUTOMATIC TESTING #####################################
展开
 我来答
雷暴狼龙5
2011-05-10 · TA获得超过165个赞
知道答主
回答量:135
采纳率:0%
帮助的人:104万
展开全部
# -*- coding: utf-8 -*-
#*** PUT YOUR ALGORITHM HERE ***

# Given some words in either English or Italian convert them to the other language
# Return the converted words.
def translator(language, word):

# create the dictionaries from the given files
english2spanish = {}
english2italian = {}
file1 = open('english2spanish.txt').readlines()
file2 = open('english2italian.txt').readlines()
for theline in file1:
words = theline.strip().split(' ')
english2spanish[words[0]]= words[1]
for theline in file2:
words = theline.strip().split(' ')
english2italian[words[0]]= words[1]

# check if the word is in the relevant dictionary
if word in english2spanish:
pass
else:
return 'Word not found'

# convert to either Italian or Spanish
word1, word2 = english2spanish[word], english2italian[word]

# check if translation is same in both Italian and Spanish
sign = 0
if word1 == word2:
sign = 1

if language == 'spanish' or language == 'Spanish':
if sign:
print 'The Spanish word for '+word+' is '+word1+' - same in both Italian and Spanish.'
else:
print 'The Spanish word for '+word+' is '+word1

if language == 'italian' or language == 'Italian':
if sign:
print 'The Italian word for '+word+' is '+word2+' - same in both Italian and Spanish.'
else:
print 'The Italian word for '+word+' is '+word2

# print out a message, e.g.
# The Spanish word for sun is sol
# The Italian word for rubbish is not found
# The Spanish word for great is grande - same in both Italian and Spanish.

# Run the tests if this is the main program:
if __name__ == '__main__':
translator('spanish','great')
#import doctest
#doctest.testmod(verbose=True)

两个文件分别命名为
english2spanish.txt
english2italian.txt
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式