-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathm04_zufall.py
More file actions
29 lines (25 loc) · 1011 Bytes
/
Copy pathm04_zufall.py
File metadata and controls
29 lines (25 loc) · 1011 Bytes
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
"""
Modul 04: Zufallszahlen
"""
from random import randint, sample
# augenzahl = randint(1, 6)
# print(augenzahl)
# Lotto-Ziehung "6 aus 49"
# Schreibe ein Programm, das 6 verschiedene zufällige
lottozahlen = []
i = 0
while len(lottozahlen) < 6:
# i += 1 # Hilfsvariable zur Iterations-Zählung
# print("Iteration:", i)
kugel = randint(1, 49) # Zufällige Zahl generieren
# print("Gezogen:", kugel)
if kugel in lottozahlen: # Check, ob sie schon einmal gezogen wurde
# print("Kugel", kugel, "war schon gezogen.")
continue # Einfach nix machen (nächste Iteration)
lottozahlen.append(kugel) # Zahl in die Liste aufnehmen
# print("Lottozahlen bisher:", lottozahlen)
print("Lottozahlen für heute:", lottozahlen)
# Die Lösung mit sample
topf = list(range(1, 50)) # Mit 49 Kugeln befüllen (warum ist die Range nach oben offen PYTHON??????)
print(topf)
print("Lottozahlen für heute:", sample(topf, k=6)) # Mit Funktion sample 6 Elemente ohne Wiederholungen ziehen