24 lines
833 B
Python
24 lines
833 B
Python
import random
|
|
|
|
|
|
class rainerSpruche():
|
|
|
|
def __init__(self, spruchDatei):
|
|
|
|
with open(spruchDatei, 'r') as f:
|
|
self.zitate = [line.strip() for line in f]
|
|
|
|
self.letzte_zahl = []
|
|
|
|
def randomSpruch(self):
|
|
self.aktuelle_zahl = random.randint(0, len(self.zitate)-1)
|
|
mögliche_zahlen = list(range(len(self.zitate)))
|
|
while self.aktuelle_zahl in self.letzte_zahl:
|
|
mögliche_zahlen.remove(self.aktuelle_zahl)
|
|
if len(mögliche_zahlen) == 0:
|
|
mögliche_zahlen = list(range(len(self.zitate)))
|
|
self.aktuelle_zahl = random.choice(mögliche_zahlen)
|
|
if len(self.letzte_zahl) >= 3:
|
|
self.letzte_zahl.pop(0)
|
|
self.letzte_zahl.append(self.aktuelle_zahl)
|
|
return(self.zitate[self.aktuelle_zahl]) |