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}")
|
||||
39
schleifen/aufgabe2.py
Normal file
39
schleifen/aufgabe2.py
Normal file
@@ -0,0 +1,39 @@
|
||||
import random
|
||||
|
||||
people = 300
|
||||
|
||||
a1 = 0
|
||||
a2 = 0
|
||||
a3 = 0
|
||||
|
||||
for _ in range(people):
|
||||
choice = random.randint(1,3)
|
||||
|
||||
match choice:
|
||||
case 1:
|
||||
a1 +=1
|
||||
case 2:
|
||||
a2 += 1
|
||||
case 3:
|
||||
a3 += 1
|
||||
case _:
|
||||
pass
|
||||
|
||||
|
||||
a1 = a1 / people * 100
|
||||
a2 = a2 / people * 100
|
||||
a3 = a3 / people * 100
|
||||
|
||||
# :.2f rundet das ergebnis auf 2 komma stellen!
|
||||
# .round geht auch aber das :.2f ist effizienter hier!
|
||||
|
||||
print(f"""
|
||||
Wahlergebnise:
|
||||
---------------------
|
||||
Wahl 1: {a1:.2f} %
|
||||
Wahl 2: {a2:.2f} %
|
||||
Wahl 3: {a3:.2f} %
|
||||
---------------------
|
||||
Gesamt: {a1+a2+a3:.2f} %
|
||||
"""
|
||||
)
|
||||
43
schleifen/aufgabe3.py
Normal file
43
schleifen/aufgabe3.py
Normal file
@@ -0,0 +1,43 @@
|
||||
# -*- coding: ansi -*-
|
||||
import random
|
||||
|
||||
credits = 5000
|
||||
|
||||
items = {
|
||||
"sofa": 899,
|
||||
"sessel": 399,
|
||||
"couchtisch": 229,
|
||||
"tv_bank": 349,
|
||||
"b<EFBFBD>cherregal": 299,
|
||||
"beistelltisch": 119,
|
||||
"stehlampe": 189,
|
||||
"teppich": 249,
|
||||
"vorh<EFBFBD>nge": 149,
|
||||
"wandregal": 99,
|
||||
"dekovase": 59,
|
||||
"wandbild": 199,
|
||||
"kissen_set": 79,
|
||||
"decke": 69,
|
||||
"pflanzenst<EFBFBD>nder": 89
|
||||
}
|
||||
|
||||
while credits > 0:
|
||||
name, cost = random.choice(list(items.items()))
|
||||
choice = input(f"Willst du {name} kaufen um {cost}<EFBFBD>? (Y/N/S/G) ")
|
||||
|
||||
match choice.upper():
|
||||
case "Y":
|
||||
if credits >= cost:
|
||||
credits -= cost
|
||||
print(f"{name} gekauft! Verbleibendes Guthaben: {credits}<EFBFBD>")
|
||||
else:
|
||||
print("Nicht genug Guthaben!")
|
||||
case "N":
|
||||
pass
|
||||
case "S":
|
||||
print("Einkauf beendet.")
|
||||
break
|
||||
case "G":
|
||||
print(f"Du hast: {credits}")
|
||||
case _:
|
||||
print("Ung<EFBFBD>ltige Eingabe!")
|
||||
30
schleifen/aufgabe4.py
Normal file
30
schleifen/aufgabe4.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import turtle
|
||||
|
||||
length = int(input("Laenge: "))
|
||||
width = int(input("Breite: "))
|
||||
color = str(input("Farbe (R/G/B): "))
|
||||
|
||||
if length > 100 or width > 100:
|
||||
length = round(length / 10)
|
||||
width = round(width / 10)
|
||||
print(f"Massstab 1:10 angewandt. Neue Laenge {length}, Neue Breite {width}")
|
||||
|
||||
t = turtle.Turtle()
|
||||
|
||||
match color.lower():
|
||||
case "r":
|
||||
t.fillcolor("red")
|
||||
case "g":
|
||||
t.fillcolor("green")
|
||||
case "b":
|
||||
t.fillcolor("blue")
|
||||
|
||||
t.begin_fill()
|
||||
for _ in range(2):
|
||||
t.forward(length)
|
||||
t.left(90)
|
||||
t.forward(width)
|
||||
t.left(90)
|
||||
t.end_fill()
|
||||
|
||||
turtle.done()
|
||||
Reference in New Issue
Block a user