[Tutor] ask

Emile van Sebille emile at fenx.com
Sun Mar 28 19:50:59 CEST 2010


On 3/28/2010 10:28 AM Shurui Liu (Aaron Liu) said...
> You know what, I just don't understand this line:
> the name of the file containing the translated output is storyAmer.txt
> and it is to located.

It sounds to me like we wants you to read in the source(british)
version, swap in the american spellings, then write the resulting text
to storyAmer.txt

You might investigate the replace (1) method of strings and use it along
the lines of:

whole_thing = whole_thing.replace(british_spelling,american_spelling)

Also, look up the parameters for open (2), specifically those related to
enabling write mode for the new file.  And the write (3) method of an
open file.

(1)
http://docs.python.org/library/stdtypes.html?highlight=replace#str.replace
(2) http://docs.python.org/library/functions.html#open
(3) http://docs.python.org/library/stdtypes.html?highlight=write#file.write

You're almost there it seems.

HTH,

Emile


> 
> 
> I don't know what kind of translated output he need. I guess:
> 
>     1. the name of the file containing the translated output is *
>     storyAmer.txt* and it is to located in a subdirectory off your cset1100py
>     *assign19*, that is *./cset1100py/assign19/storyAmer.txt* directory named
> 
> 
> What kind of translated output do you want?
> 
> (1) A list of wrong words and a list of right words, like this:
> 
>      Wrong words in the text are: ......
> 
>       Right words should be: ......
> 
> 
> 
> OR
> 
> 
> 
> (2) The content of the text but has already been translated, like this:
> 
> 
> 
> I am really glad that I took CSET 1100.
> We get to *analyze* all sorts of real-world problems.
> We also have to *memorize* some programming language syntax.
> But, the *center* of our focus is game programming and it is fun.
> Our instructor adds *color* to his lectures that make them interesting.
> It is an honour to be part of this class!
> 
> 
> 
> 在 2010年3月28日 下午12:26,Shurui Liu (Aaron Liu)<shurui91 at gmail.com>写道:
> 
>> Since English is not my native language, so I got confused by some
>> requirement of my assignment. I already done, just want to make sure what I
>> did is what the assignment required, thank you!
>>
>> BTW, I don't know how to do this:
>> If I want to fix some wrong words in a text file, how can I print out the
>> right/fixed text file? Like this:
>> My favor colour is blue. → My favourite color is blue. (Just print out the
>> right thing directly)
>>
>> Thank you!
>>
>> assignment:
>>
>> 1 Write a Python program named british2american.py
>>   that reads the contents of a text file, looks for occurances of uniquely British spelling, and translates the occurances into the acceptes American spelling.
>>
>> 1
>> Specifically, you will be looking for the following words: colour, analyse, memorise, centre and recognise. If found, they are to be
>> replaced with color, analyze, memorize, center and recognize.
>>
>> 1 The following is needed for you to write your program:
>>
>> 1 the name of the file containing the text to be translated is
>> storyBrit.txt
>>   and it is to be located in your cset1100py directory. Copy it from this
>> link<http://cset.sp.utoledo.edu/cset1100py/storyBrit.txt>
>>   to the designated location.
>>
>> 1 your program, british2american.py, should be located in your cset1100py
>>   directory on et791
>>
>> 1 the name of the file containing the translated output is storyAmer.txt
>>   and it is to located in a subdirectory off your cset1100py directory named
>> assign19, that is ./cset1100py/assign19/storyAmer.txt
>>
>> 1 the original file, storyBrit.txt, should be left unchanges
>> This is british2american.py
>> # Translate wrong British words
>> #Create an empty file
>> print "\nReading characters from the file."
>> raw_input("Press enter then we can move on:")
>> text_file = open("storyBrit.txt", "r+")
>> whole_thing = text_file.read()
>> print whole_thing
>> raw_input("Press enter then we can move on:")
>> print "\nWe are gonna find out the wrong British words."
>> # Press enter and change the wrong words
>> if "colour" in whole_thing:
>>      print "The wrong word is 'colour' and the right word is 'color'"
>> if "analyse" in whole_thing:
>>      print "the wrong word is 'analyse' and the right word is 'analyze'"
>> if "memorise" in whole_thing:
>>      print "the wrong word is 'memorise' and the right word is 'memorize'"
>> if "centre" in whole_thing:
>>      print "the wrong word is 'centre' and the right word is 'center'"
>> if "recognise" in whole_thing:
>>      print "the wrong word is 'recognise' and the right word is 'recognize'"
>> if "honour" in whole_thing:
>>      print "the wrong word is 'honour' and the right word is 'honor'"
>> # We are gonna save the right answer to storyAmer.txt
>> w = open('storyAmer.txt', 'w')
>> w.write('I am really glad that I took CSET 1100.')
>> w.write('\n')
>> w.write('We get to analyse all sorts of real-world problems.\n')
>> w.write('\n')
>> w.write('We also have to memorize some programming language syntax.')
>> w.write('\n')
>> w.write('But, the center of our focus is game programming and it is fun.')
>> w.write('\n')
>> w.write('Our instructor adds color to his lectures that make them
>> interesting.')
>> w.write('\n')
>> w.write('It is an honor to be part of this class!')
>> w.close()
>>
>> This is storyAmer.txt(right one):
>> I am really glad that I took CSET 1100.We get to analyze all sorts of
>> real-world problems.We also have to memorize some programming language
>> syntax. But, the center of our focus is game programming and it is fun.Our
>> instructor adds colour to his lectures that make them interesting.It is an
>> honor to be part of this class!
>>
>> This is storyBrit.txt(wrong one):
>> I am really glad that I took CSET 1100.We get to analise all sorts of
>> real-world problems.We also have to memorise some programming language
>> syntax. But, the centre of our focus is game programming and it is fun.Our
>> instructor adds colour to his lectures that make them interesting.It is an
>> honour to be part of this class!
>>
>>
>> Thank you very much!
>>
>>
>>
>> --
>> Shurui Liu (Aaron Liu)
>> Computer Science&  Engineering Technology
>> University of Toledo
>>
> 
> 
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor




More information about the Tutor mailing list