-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.py
81 lines (69 loc) · 2.63 KB
/
Main.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import Words
def get_word_length():
word_length = 0
while word_length == 0:
try:
word_length = int(input('Kor mange bokstavar er det i ordet?\n'))
except:
print('Du må skrive inn eit tal. Prøv igjen.\n')
return word_length
def get_if_letter_in_word(letter):
answer = ''
while answer == '':
answer = input('\nInneheldt ordet bokstaven ' + letter +
'? Ja eller nei?\n')
if (answer == 'Ja') or (answer == 'ja'):
return True
elif (answer == 'Nei') or (answer == 'nei'):
return False
else:
answer = ''
print('Du må skrive enten ja eller nei\n')
def get_letter_pos_list(letter, words):
letter_pos_list = ''
while letter_pos_list == '':
try:
while letter_pos_list == '':
letter_pos_list = input(
'Skriv inn nummer på posisjonar i ordet der bokstaven ' +
letter + ' er med:\n').split()
if len(letter_pos_list) == 0:
letter_pos_list = ''
print('Du må skrive inn minst 1 tal. Prøv igjen\n')
for i in range(len(letter_pos_list)):
letter_pos_list[i] = int(letter_pos_list[i]) - 1
if (min(letter_pos_list) < 0) or (
(max(letter_pos_list) + 1) > words.word_length):
letter_pos_list = ''
print('Tal må vere større enn null og mindre enn ordlengde.\n')
except:
letter_pos_list = ''
print('Du må skrive inn tal. Prøv igjen.\n')
return letter_pos_list
def loop(words):
while True:
letter = words.get_letter_to_guess()
answer = get_if_letter_in_word(letter)
if answer:
letter_pos_list = get_letter_pos_list(letter, words)
for element in letter_pos_list:
words.set_words_with_letter_in_pos(letter, element)
for i in range(words.word_length):
if i not in letter_pos_list:
words.set_words_without_letter_in_pos(letter, i)
else:
words.set_words_without_letter(letter)
if len(words.get_words()) == 1:
print('\nOrdet er ' + words.get_words()[0])
break
elif len(words.get_words()) == 0:
print('\nOrdet er ikkje i ordboka')
break
print(words.get_words())
def main():
words = Words.Words()
words.word_length = get_word_length()
words.set_words_with_length(words.word_length)
loop(words)
if __name__ == '__main__':
main()