Hallo
Ich hab das Programm für ein anderes
Lotto-System ein wenig umgeschrieben. Bei diesem System gibt es folgendes zu beachten für ein Gewinn:
Zahl (max 5) + Stern (max 2)
Gewinn ab 1 Zahl + 2 Sterne, zwei Zahlen + 0 Stern.
Nun habe ich zweimal die gleiche Print-Anweisung und eine 'if', 'elif' und 'else' Abfrage. Gäbe es eine Möglichkeit, dies alles zu verkürzen bzw zu vereinfachen?
mfg
Code: Alles auswählen
#!/usr/bin/env python
# coding: utf-8
from __future__ import print_function
import requests
from bs4 import BeautifulSoup
URL = 'http://www.euro-millionen.org'
def hole_ziehung():
soup = BeautifulSoup(requests.get(URL).text)
lottozahlen = [
int(n.string) for n in soup.select('div#results-content li')
]
result = [lottozahlen]
zusatz_zahlen = []
zusatz_zahlen.append(lottozahlen.pop(-2,))
zusatz_zahlen.append(lottozahlen.pop(-2,))
result.append(zusatz_zahlen)
return result
def vergleiche(tipp, ziehung):
return sorted(set(tipp[0]) & set(ziehung[0])), sorted(set(tipp[1]) & set(ziehung[1]))
def main():
#ziehung = hole_ziehung()
ziehung = [[20, 21, 27, 33, 40], [2, 6]]
print(ziehung)
tipps = [
[[1, 5, 21, 33, 48], [2, 6]],
[[14, 20, 32, 33, 40], [3, 7]],
]
for tipp_nr, tipp in enumerate(tipps, 1):
print('{0:>1}. Tipp:'.format(tipp_nr), end=' ')
richtige, sind_sterne_richtig = vergleiche(tipp, ziehung)
if len(richtige) >= 1 and len(sind_sterne_richtig) == 2:
print('{0} richtige Zahlen: "{1}": Sterne: "{2}"'.format(
len(richtige),
', '.join(map(str, richtige)),
'{0}'.format(', '.join(map(str, sind_sterne_richtig))) if sind_sterne_richtig else 'falsch'
)
)
elif len(richtige) >= 2:
print('{0} richtige Zahlen: "{1}": Sterne: "{2}"'.format(
len(richtige),
', '.join(map(str, richtige)),
'{0}'.format(', '.join(map(str, sind_sterne_richtig))) if sind_sterne_richtig else 'falsch'
)
)
else:
print('Leider kein Gewinn')
if __name__ == '__main__':
main()