Mittwoch, 10. Dezember 2014

Aufgaben für 10.12.2014

Aufgaben

Vorschlag für "Augenzählen":

import random
sum=0
cube_1=0
cube_2=0

augenzahlen=[0,0,0,0,0,0,0,0,0,0,0,0]
for i in range(1000):
cube_1=random.randint(1,6)
cube_2=random.randint(1,6)
sum=cube_1+cube_2
augenzahlen[sum-1]=int(augenzahlen[sum-1])+1
print(augenzahlen)
print("Am haeufigsten wurde", augenzahlen.index(max(augenzahlen))+1,"gewuerfelt, und zwar ",max(augenzahlen),"mal.")


(Achtung, die letzte Zeile wird hier verteilt auf zwei Zeilen angezeigt. Für das Programm muss sie aber in einer Zeile sein.)

Vorschlag für "Schaltjahr":

jahr=input("Gib ein Jahr ein:")
jahr=int(jahr)
if jahr%4!=0:
print(jahr, " ist kein Schaltjahr")
else:
if jahr%100==0 and jahr%400==0:
print(jahr, " ist ein Schaltjahr")
if jahr%100==0 and jahr%400!=0 and jahr%4==0:
print(jahr, " ist ein Schaltjahr")

Vorschlag für "Münzenzählen":

betrag= float(input("Gib einen Betrag ein (z.B. 3.56): (Bitte Punkt statt Komma nutzen):"))
zwei_euro=0
ein_euro=0
cent_50=0
cent_20=0
cent_10=0
cent_5=0
cent_2=0
cent_1=0


while round(betrag,2)>0:
betrag=round(betrag,2)
if betrag >=2:
zwei_euro=zwei_euro+1
betrag=betrag-2
continue
if betrag>=1:
ein_euro=ein_euro+1
betrag=betrag-1
continue
if betrag>=0.5:
cent_50=cent_50+1
betrag=betrag-0.50
continue
if betrag>=0.20:
cent_20=cent_20+1
betrag=betrag-0.20
continue
if betrag>=0.1:
cent_10=cent_10+1
betrag=betrag-0.1
continue
if betrag>=0.05:
cent_5=cent_5+1
betrag=betrag-0.05
continue
if betrag>=0.02:
cent_2=cent_2+1
betrag=betrag-0.02
continue
if betrag>=0.01:
cent_1=cent_1+1
betrag=betrag-0.01
print("Es werden",zwei_euro,"mal 2 Euro,",ein_euro,"mal 1 Euro,", cent_50,"mal 50ct,", cent_20,"mal 20ct,", cent_10,"mal 10ct,", cent_5,"mal 5ct,",cent_2,"mal 2ct und",cent_1,"mal 1ct Muenzen benoetigt.")


Mittwoch, 3. Dezember 2014

Uhrzeiten eines Tages ausgeben

Gesucht ist ein Programm, dass alle möglichen Uhrzeiten eines Tages ausgibt. Also von "00:00:00" bis "23:59:59"

Von Hand ist das natürlich uferlos, da es 86400 Möglichkeiten gibt.

Nested loops, also "Schleifen in Schleifen" nehmen uns aber hier viel Arbeit ab.

Hier ist der Code: