I have this code:
def random_answerlist(self):
self.li = []
self.winning_button = random.randint(0, 3)
i = 0
while i < 20 and len(self.li) is not 4:
if i == self.winning_button:
self.li.append(self.flags[self.current_flag][0])
else:
new_value = self.random_value()
if self.flags[new_value][0] not in self.li:
self.li.append(self.flags[new_value][0])
i += 1
return self.li
The only problem with it is that the first if-case may happen several times which should be impossible. I have searched for a good explanation to this and I can't find any.
Oh, I know the code isn't the best. But I'm kind of new to python (just a month or so) and thought this might work, but it didn't!
Do you guys know why? =)