Benutzer-Werkzeuge

Webseiten-Werkzeuge


Seitenleiste

ws1718:schatzsucheprinzip

Schatzsuche-Prinzip

Das Schatzsuche-Prinzip ist eine art der Fortbewegungsabfrage, die bei einer der Hausaufgaben im Programmierkurs vorkam. Dieses bildete die Basis für die Umsetzung des „milkyways“ im Hauptcode.


# Schatzsuche:
anweisung=raw_input("Bitte Anweisung mit Leerzeichen getrennt angeben:")
 
koordinate=[0,0]
richtung=1
 
######
temp=""
worte=[]
for i in anweisung:                                             
    if i == " " or i == "." or i == "," or i == ";":        
        if temp!="":                                        
            if worte.count(temp)==0:                        
                worte.append(temp)                        
        temp=""                                            
    else:                                   
        temp=temp+i                                         
######
for i in worte:
    if i != " ":
        if i== "R":
            richtung+=1
            if richtung==5:
                richtung=1
        elif i=="L":
            richtung-=1
            if richtung==0:
                richtung=4
        else:
            if richtung==1:
                koordinate[1]=koordinate[1]+int(i)
            if richtung==2:
                koordinate[0]=koordinate[0]+int(i)
            if richtung==3:
                koordinate[1]=koordinate[1]-int(i)
            if richtung==4:
                koordinate[0]=koordinate[0]-int(i)
print(koordinate)
ws1718/schatzsucheprinzip.txt · Zuletzt geändert: 2018/04/07 17:47 von daphna_99