initial commit
This commit is contained in:
30
schleifen/aufgabe1.py
Normal file
30
schleifen/aufgabe1.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import random
|
||||
|
||||
#utf-8 erlaubt keine <20>e<EFBFBD>
|
||||
|
||||
weight = {
|
||||
"Kirsche": 8,
|
||||
"Orange": 5,
|
||||
"Zitrone": 5,
|
||||
"Apfel": 7,
|
||||
}
|
||||
|
||||
count = {
|
||||
"Kirsche": 0,
|
||||
"Orange": 0,
|
||||
"Zitrone": 0,
|
||||
"Apfel": 0,
|
||||
}
|
||||
|
||||
total_weight = 0
|
||||
target_weight = 250
|
||||
|
||||
while total_weight < target_weight - 5:
|
||||
fruit = random.choice(list(weight.keys()))
|
||||
total_weight += weight[fruit]
|
||||
count[fruit] += 1
|
||||
|
||||
print("Zusammensetzung")
|
||||
for fruit, amount in count.items():
|
||||
print(f"{fruit}: {amount} Stueck")
|
||||
print(f"Gesamtgewicht: {total_weight}")
|
||||
Reference in New Issue
Block a user