Übersetzungen dieser Seite:
Inhaltsverzeichnis

Moritz

Hi 8-) :-D

Zahlenraten

zahlenraten.py
# -*- coding: utf-8 -*-
import random
x=random.randint(1,1000)
a=1
versuche=0
while a >0:
    a=input("Errate meine Zahl:")
    versuche+=1
    if a==x:
        print "gewonnen"
        break
    elif a>x:
        print"zu hoch"
    else:
        print"zu tief"
print "game over"
print "%i versuche"%versuche

c

für dieses programm braucht man easygui: http://easygui.sf.net

zahlenraten2.py
# -*- coding: utf-8 -*-
import random
import easygui as e
e.msgbox("start")
x=random.randint(1,1000)
liste=["kalter","dummer","idiotischer","bloeder","kleiner","feiner","doofer","schrumpfkopfiger","heisser","dummer","komischer"]
liste2=["sessel","tisch","idiot","computer","zug","magnet","hamster","kasten","ofen","topf"]
a=1
versuche=0
ergebnis=""
history = ""
 
while a >=0:
    versuche+=1
    if versuche >1:
        history += "\n" + ergebnis
        e.codebox("bisher:", "bla", history)
    a = e.integerbox("Errate meine Zahl:","rateversuch %i"%versuche,500,1,1000)
    if a==x:
        e.msgbox("gewonnen du %s %s %s"%(random.choice(liste),random.choice(liste),random.choice(liste2))) 
        break
    elif a>x:
        ergebnis = "%i ist zu hoch du %s %s %s"%(a,random.choice(liste),random.choice(liste),random.choice(liste2))
    else:
        ergebnis = "%i ist zu tief du %s %s %s"%(a,random.choice(liste),random.choice(liste),random.choice(liste2))
msg = "%i Versuche" % versuche
e.msgbox(msg, "game over")

Hausbau

schild2.py
# -*- coding: utf-8 -*-
import random as r
import turtle as t
t.speed(0)
 
def haus(hoehe):
    """zeichne ein haus"""
    t.lt(90)
    t.fd(hoehe)
    t.rt(90)
    t.fd(50)
    t.rt(90)
    t.fd(hoehe)
    t.rt(90)
    t.fd(50)
    t.rt(90)
    t.fd(hoehe)
    t.rt(45)
    t.fd(35)
    t.rt(90)
    t.fd(35)
    t.pu()
    t.rt(135)
    t.fd(50)
    t.rt(180)
    t.rt(90)
    t.fd(hoehe)
    t.lt(90)
 
 
def weg():
    """gehe den weg"""
    t.pu()
    t.fd(-2000)
    for x in range(40):
       t.pu()
       t.fd(50)
       t.pd()
       haus(r.randint(10,160))
    t.rt(90)
    t.fd(200)
    t.lt(90)
    t.pd()
 
t.pu()
t.left(90)
t.fd(150)
t.right(90)
t.fd(1000)
t.pd()
for y in range(3):
	weg()
 
x = raw_input("enter trücken")

http://docs.python.org/library/turtle.html


de/personen/moritz/start.txt · Zuletzt geändert: 2011/02/10 10:06 von moritz