#!/usr/bin/env python
# -*- coding: utf8 -*-
import sys, datetime
# Function performing the tests.
def is_leap(year):
if not year%4:
if not year%100:
if not year%400:
return 'Das Jahr %04d ist ein Schaltjahr' % year
return'Das Jahr %04d ist kein Schaltjahr' % year
return 'Das Jahr %04d ist ein Schaltjahr' % year
else:
return' Das Jahr %04d ist kein Schaltjahr' % year
print 'Ist ein Jahr ein Schaltjahr?'
print 'Beenden mit Eingabe "quit"'
while True:
# This loop truely runs forever. The script will never leave it
# until the script is terminated using sys.exit().
while True:
# This loop is repeated until a valid integer is entered.
try:
year = raw_input('Jahr?> ')
year = int(year)
except EOFError:
# This happens when Ctrl+D is hit.
print "Bye!"
sys.exit(0)
except KeyboardInterrupt:
# This happens when Ctrl+C is hit.
print "Bye!"
sys.exit(0)
except:
if year == "quit":
print "Bye!"
sys.exit(0)
else:
print "Kann nicht in Integer umgewandelt werden:", year
else:
break
print is_leap(year)