This commit is contained in:
Oliver Hofmann
2024-09-23 13:22:12 +02:00
commit 45c4160142
69 changed files with 1906 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
# Ausgabe von Geldbeträgen in einer speziellen Formatierung
def main():
for money in [100123345, 100123305, 5]:
print(format_money_string(money))
# Funktion zur Formatierung von Geldbeträgen
def format_money_string(cents):
euros = cents // 100
cents = cents % 100
thousands = euros // 1000
euros = euros % 1000
millions = thousands // 1000
thousands = thousands % 1000
if millions > 0:
return f'{millions}.{thousands:03}.{euros:03},{cents:02}'
elif thousands > 0:
return f'{thousands}.{euros:03},{cents:02}'
else:
return f'{euros},{cents:02}'
# Start des Programms
main()
+9
View File
@@ -0,0 +1,9 @@
# Rechenmaschine
while True:
repeat = input("Soll noch eine Addition durchgeführt werden? (j/n): ")
if repeat == 'n':
break
zahl1 = float(input("Erste Zahl: "))
zahl2 = float(input("Zweite Zahl: "))
print(f"Die Summe beträgt {zahl1 + zahl2}")
+6
View File
@@ -0,0 +1,6 @@
# Ausgabe eines Countdowns von 10 bis 0
start = 10
while start >= 0:
print(start)
start -= 1
+13
View File
@@ -0,0 +1,13 @@
# Ermittlung, ob das Farbband gewechselt werden muss
# (immer an geraden Tagen)
# Eingabe
day = int(input('Welchen Kalendartag haben wir heute (1-31): '))
# Berechnung
if day % 2 == 0:
print('Wechsel das Farbband!')
else:
print('Alles gut!')
+15
View File
@@ -0,0 +1,15 @@
# Ausgabe von Geldbeträgen in einer speziellen Formatierung
def main():
for money in [120, 90, 100, 102, 2]:
print(format_money_string(money))
# Funktion zur Formatierung von Geldbeträgen
def format_money_string(money):
euros = money // 100
cents = money % 100
return f'{euros},{cents:02}'
# Start des Programms
main()
+8
View File
@@ -0,0 +1,8 @@
# Ausgabe von Quadratzahlen
MAX_NUM = 10
i = 0
while i <= MAX_NUM:
print(f"{i} quadriert ist {i*i}")
i += 1
+6
View File
@@ -0,0 +1,6 @@
# Temperaturumrechnung
f = float(input("Geben Sie die Temperatur in Fahrenheit ein: "))
c = (f - 32) * 5 / 9
print(f"Die Temperatur in Celsius beträgt {c:.1f}")
+9
View File
@@ -0,0 +1,9 @@
# Berechnung der Uhrzeit für Menschen
sec = int(input("Wie viele Sekunden sind seit Mitternacht vergangen? "))
hours = sec // 3600
minutes = (sec % 3600) // 60
seconds = sec % 60
print (f"Es ist {hours:02}:{minutes:02}:{seconds:02}.")