Python Kalender
Verfasst: Freitag 20. Dezember 2019, 12:45
Hallo,
unsere Aufgabe ist es einen Kalender zu programmieren.
Leider komme ich bei der Darstellung nicht richtig weiter.
Hier der Code:
Die Datumszahlen müssen noch unter die richtigen Tage.
Wir benutzen bislang nur die Standardbefehle wie if, while, for...
Vielen Dank für die Antworten und einen schönen Tag noch!
unsere Aufgabe ist es einen Kalender zu programmieren.
Leider komme ich bei der Darstellung nicht richtig weiter.
Hier der Code:
Code: Alles auswählen
import math
jahr = 2019 # input("Geben Sie das Jahr ein: ")
monat = 12 # input("Geben Sie den Monat als Zahl ein: ")
tag_name = ['Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag', 'Sonntag']
tag_zahl = [1, 2, 3, 4, 5, 6, 7]
tag = 1
monat_name = ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember']
tage_zahl = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
if type(jahr) is not int:
print("Ungültige Eingabe! Bitte wiederholen!")
jahr = input("Bitte geben Sie das Jahr erneut ein: ")
if type(monat) is not int:
print("Die Eingabe ist ungültig! Bitte wiederholen!")
monat = input("Bitte geben Sie den Monat erneut ein: ")
monat = int(monat)
while monat > 12 or monat < 1:
print("Die Eingabe des Monats ist ungültig!")
monat = int(input("Bitte geben Sie den Monat erneut ein: "))
jahr = int(jahr)
while jahr < 1 or jahr > 9999:
print("Das Jahr ist ungültig!")
jahr = int(input("Bitte geben Sie das Jahr erneut ein: "))
jahr2 = jahr
if monat < 3:
jahr -= 1
w = ((tag + math.floor(2.6 * ((monat + 9) % 12 + 1) - 0.2) + jahr % 100 + math.floor(jahr % 100 / 4) + math.floor(jahr / 400) - 2 * math.floor(jahr / 100) - 1) % 7 + 7) % 7 + 1
# Quelle: https://de.wikipedia.org/wiki/Wochentagsberechnung#Programmierung
print()
print("Jahr: ", jahr)
print("Monat: ", monat)
# 1 = Januar, ... , 12 = Dezember
print("Tagesanzahl: ", w)
# 1 = Montag, ... , 7 = Sonntag
print("Anzahl der Tage des Monats:",tage_zahl[monat-1])
print("Tag: ", tag)
print()
print("-----------------------------")
print()
if monat == 1:
print(" Januar", jahr2)
if monat == 2:
print(" Februar", jahr2)
if monat == 3:
print(" März", jahr2)
if monat == 4:
print(" April", jahr2)
if monat == 5:
print(" Mai", jahr2)
if monat == 6:
print(" Juni", jahr2)
if monat == 7:
print(" Juli", jahr2)
if monat == 8:
print(" August", jahr2)
if monat == 9:
print(" September", jahr2)
if monat == 10:
print(" Oktober", jahr2)
if monat == 11:
print(" November", jahr2)
if monat == 12:
print(" Dezember", jahr2)
x1 = 1
print("Mo", "Di", "Mi", "Do", "Fr", "Sa", "So", end="")
tage = ["Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"]
print("")
for x in range(1, tage_zahl[monat-1]+1):
if x < 10:
print("",x, end=" ")
if x > 9:
print(x, end=" ")
if not x % 7:
print(" ")
print()
Wir benutzen bislang nur die Standardbefehle wie if, while, for...
Vielen Dank für die Antworten und einen schönen Tag noch!