Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class spell_spanish:
- def __init__(self):
- pass
- #get a random letter that is not contained in the word passed as an argument
- def get_random_letter(self, current_word = "", uppercase = True):
- letter_alphabet = ascii_uppercase
- if(uppercase == False):
- letter_alphabet = ascii_lowercase
- while True:
- random_letter = random.choice(letter_alphabet)
- if(current_word.find(random_letter) < 0):
- break
- return random_letter
- #get a random letter that is not contained in the word passed as an argument
- def get_random_letter(self, current_word = "", uppercase = True):
- letter_alphabet = ascii_uppercase
- if(uppercase == False):
- letter_alphabet = ascii_lowercase
- while True:
- random_letter = random.choice(letter_alphabet)
- if(current_word.find(random_letter) < 0):
- break
- return random_letter
- #get a string with four different letters, the first one (passed as parameter) is the correct choice
- #if uppercase is false, the four letters will be lowercase, otherwrise, they will be uppercase
- def get_four_letters(self, correct_letter, uppercase = True):
- if(uppercase == True):
- correct_letter = correct_letter.upper()
- else:
- correct_letter = correct_letter.lower()
- four_letters = correct_letter
- for i in range (1,4):
- new_letter = self.get_random_letter(four_letters, uppercase)
- four_letters += new_letter
- return four_letters
- #make random 4 letters of each letter of a word
- #TODO change len(word)-1 back to 0
- def randomize_word(self, word, uppercase = True):
- if(uppercase):
- word = word.upper()
- else:
- word = word.lower()
- for i in range (0, len(word)):
- four_letters = self.get_four_letters(word[i],uppercase)
- list_of_characters = list(four_letters)
- random.shuffle(list_of_characters)
- four_scrambled_letters = ''.join(list_of_characters)
- correct_letter_index = four_scrambled_letters.find(word[i])
- self.show_letter_options(four_scrambled_letters)
- self.correct_input(correct_letter_index)
- clear_screen()
- display_message("FELICIDADES!")
- #wait for the user to input the correct option (0-3)
- def correct_input(self, correct_letter_index):
- while True:
- button1 = GPIO.input(6)
- button2 = GPIO.input(13)
- button3 = GPIO.input(19)
- button4 = GPIO.input(26)
- if(button1):
- time.sleep(0.2)
- if(correct_letter_index == 0):
- print("Correcto")
- break
- else:
- print("Incorrecto")
- elif(button2):
- time.sleep(0.2)
- if(correct_letter_index == 1):
- print("Correcto")
- break
- else:
- print("Incorrecto")
- elif(button3):
- time.sleep(0.2)
- if(correct_letter_index == 2):
- print("Correcto")
- break
- else:
- print("Incorrecto")
- elif(button4):
- time.sleep(0.2)
- if(correct_letter_index == 3):
- print("Correcto")
- break
- else:
- print("Incorrecto")
- def show_letter_options(scrambled_letters):
- matrix.display_letter(0,scrambled_letters[0])
- matrix.display_letter(1,scrambled_letters[1])
- matrix.display_letter(2,scrambled_letters[2])
- matrix.display_letter(3,scrambled_letters[3])
- def run(self):
- textToSpeech.say("Deletrea Hola")
- self.randomize_word("Hola")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement