Week 8: Text
Write a program that allows the user to enter a sentence which the computer will then spell check.
Hint: Use the Dictionary class to look up the definition of each word.
If no definition exists then it can be assumed the word is spelt incorrectly.Example:
INPUT: The kwick brown fox jumps over a lazey dog.
OUTPUT: “kwick” and “lazey” are not correct.
Scrivi un programma per controllare la correttezza ortografica di una frase inserita dall’utente.
Suggerimento: utilizza la libreria Dictionary per controllare la definizione di ciascuna parola.
Se non esiste una definizione allora si può concludere che la parola sia stata scritta in modo scorretto.
Soluzione
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
TextWindow.Write("Inserisci un testo in inglese: ") testo=TextWindow.Read() '------------------------------------------------------------ '------------------------------------------------------------ ELENCO="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" parole=0 IN_PAROLA=0 parola="" For i=1 To Text.GetLength(testo) car=Text.GetSubText(testo,i,1) If Text.IsSubText(ELENCO,car) Then IN_PAROLA=1 parola=parola+car Else If IN_PAROLA=1 Then IN_PAROLA=0 GestisciParola() parola="" EndIf EndIf EndFor '------------------------------------------------------------ If IN_PAROLA=1 Then GestisciParola() EndIf '------------------------------------------------------------ if parole=0 Then TextWindow.WriteLine("The sentence is correct.") ElseIf parole=1 Then TextWindow.WriteLine(" is not correct.") Else TextWindow.WriteLine(" are not correct.") endif '------------------------------------------------------------ '------------------------------------------------------------ Sub GestisciParola risposta=Dictionary.GetDefinition(parola) If Text.GetLength(risposta)=0 Then If parole > 0 then TextWindow.Write(" and ") endif TextWindow.Write("'" + parola + "'") parole=parole+1 EndIf EndSub |