Skip to content

Commit faf2b4e

Browse files
author
Yari's Apple Minion
committed
Aggiungi documentazione in inglese per le funzioni in main.py e configura flake8 per il controllo dello stile del codice
1 parent 12308f8 commit faf2b4e

File tree

2 files changed

+44
-21
lines changed

2 files changed

+44
-21
lines changed

.flake8

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[flake8]
2+
max-line-length = 79
3+
blank-lines = 2

main.py

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,21 @@
55
import time
66
import json
77

8-
# Carica la configurazione dal file JSON
8+
99
def load_config(config_file):
10+
"""
11+
Load configuration from a JSON file.
12+
13+
Args:
14+
config_file (str): The path to the JSON configuration file.
15+
16+
Returns:
17+
dict: The configuration data loaded from the file.
18+
"""
1019
with open(config_file, 'r', encoding='utf-8') as file:
1120
return json.load(file)
1221

22+
1323
config = load_config('config.json')
1424

1525
NAME_FILE = config['NAME_FILE']
@@ -19,48 +29,52 @@ def load_config(config_file):
1929
LENGHT_PER_WORD = config['LENGHT_PER_WORD']
2030
DIFFICULTY = config['DIFFICULTY']
2131

32+
2233
def load_file_word_list(dirfile):
2334
"""
24-
Carica la lista di parole da un file.
35+
Load the word list from a file.
2536
2637
Args:
27-
dirfile (str): Il percorso del file da cui caricare le parole.
38+
dirfile (str): The path to the file from which to load the words.
2839
2940
Returns:
30-
list: Una lista di parole caricate dal file.
41+
list: A list of words loaded from the file.
3142
"""
3243
words = []
3344
try:
3445
with open(dirfile, 'r', encoding='utf-8') as fil:
3546
words = fil.read().splitlines()
3647
except FileNotFoundError:
37-
print(f"Errore: Il file {dirfile} non è stato trovato.")
48+
print(f"Error: The file {dirfile} was not found.")
3849
except IOError:
39-
print(f"Errore: Impossibile leggere il file {dirfile}.")
50+
print(f"Error: Unable to read the file {dirfile}.")
4051
return words
4152

53+
4254
def randomword(wordlist):
4355
"""
44-
Seleziona una parola casuale dalla lista di parole.
56+
Select a random word from the word list.
4557
4658
Args:
47-
wordlist (list): La lista di parole da cui selezionare.
59+
wordlist (list): The list of words to select from.
4860
4961
Returns:
50-
str: Una parola casuale dalla lista.
62+
str: A random word from the list.
5163
"""
5264
ind = random.randint(0, len(wordlist)-1)
5365
return wordlist[ind]
5466

67+
5568
def generate(wordlist):
5669
"""
57-
Genera una lista di parole dove il giocatore deve indovinare quella corretta.
70+
Generates a list of words where the player
71+
has to guess the correct one.
5872
5973
Args:
60-
wordlist (list): La lista di parole da cui generare.
74+
wordlist (list): The list of words to generate from.
6175
6276
Returns:
63-
tuple: Una lista di parole generate casualmente e la parola corretta.
77+
tuple: A list of randomly generated words and the correct word
6478
"""
6579
debuglist = set()
6680
max_words = random.randint(MIN_NUM_WORD, MAX_NUM_WORD)
@@ -74,39 +88,44 @@ def generate(wordlist):
7488
newlistwords = list(debuglist)
7589
return (newlistwords, newlistwords[random.randint(0, len(newlistwords))])
7690

91+
7792
def verifyword(word, masterpassword):
7893
"""
79-
Verifica se la parola inserita è corretta.
94+
Verifies if the entered word is correct.
8095
8196
Args:
82-
word (str): La parola inserita dall'utente.
83-
masterpassword (str): La parola corretta.
97+
word (str): The word entered by the user.
98+
masterpassword (str): The correct word.
8499
85100
Returns:
86-
bool: True se la parola è corretta, False altrimenti.
101+
bool: True if the word is correct, False otherwise.
87102
"""
88103
return word == masterpassword
89104

105+
90106
def letinword(word, masterpassword):
91107
"""
92-
Conta il numero di lettere corrette nella parola masterpassword dalla parola inserita.
108+
Counts the number of correct letters in the masterpassword from the
109+
entered word.
93110
94111
Args:
95-
word (str): La parola inserita dall'utente.
96-
masterpassword (str): La parola corretta.
112+
word (str): The word entered by the user.
113+
masterpassword (str): The correct word.
97114
98115
Returns:
99-
str: Il numero di lettere corrette rispetto alla lunghezza della parola corretta.
116+
str: The number of correct letters relative to the length of the
117+
correct word.
100118
"""
101119
nletter = 0
102120
for letter in word:
103121
if letter in masterpassword:
104122
nletter += 1
105123
return str(nletter) + "/" + str(len(masterpassword))
106124

125+
107126
def main():
108127
"""
109-
Funzione principale del gioco.
128+
Main function of the program.
110129
"""
111130
print("Excecuting Debug of the secretCodes.db", "")
112131
print("")
@@ -161,6 +180,7 @@ def main():
161180
print("")
162181
print("NO MORE ATTEMPTS AVAILABLE")
163182

183+
164184
if __name__ == '__main__':
165185
main()
166186
print('')

0 commit comments

Comments
 (0)