Python :: Aufgabe #86 :: Lösung #4

9 Lösungen Lösungen öffentlich
#86

Stein, Papier, Schere, Echse, Spock

Anfänger - Python von Energy - 24.09.2015 um 15:22 Uhr
Programmiere das Spiel Stein, Papier, Schere, Echse, Spock, sodass man selbst eine Figur auswählen kann und der Computer eine zufällige Figur auswählt. Ermittele dann, wer diese Partie gewonnen hat.
#4
vote_ok
von Dorn2504 (20 Punkte) - 09.11.2015 um 16:24 Uhr
Quellcode ausblenden Python-Code
import random
random.seed()
computerwahl = random.randint(0, 4)

tie = "Unentschieden!"
viktory = "Sie haben Gewonnen!"
lose = "Sie haben Verloren!"
playerwahl = input("Stein:1, Papier:2, Schere:3, Echse:4 oder Spock:5? ")

def player(playerwahl, computerwahl):
    if playerwahl == 1:
        player_stein(computerwahl)
    elif playerwahl == 2:
        player_papier(computerwahl)
    elif playerwahl == 3:
        player_schere(computerwahl)
    elif playerwahl == 4:
        player_echse(computerwahl)
    elif playerwahl == 5:
        player_spook(computerwahl)
    else:
        print "Falsche Eingabe! "

def player_stein(computerwahl):
    if computerwahl == 0:
        print tie
    elif computerwahl == 1:
        print lose
    elif computerwahl == 2:
        print viktory
    elif computerwahl == 3:
        print vikory
    elif computerwahl == 4:
        print lose
    else:
        print "Falsche Eingabe!"
def player_schere(computerwahl):
    if computerwahl == 0:
        print lose
    elif computerwahl == 1: 
        print viktory
    elif computerwahl == 2: 
        print tie
    elif computerwahl == 3:
        print viktory
    elif computerwahl == 4:
        print lose
    else:
        print "Falsche Eingabe!"
def player_papier(computerwahl):
    if computerwahl == 0:
        print viktory
    elif computerwahl == 1: 
        print tie
    elif computerwahl == 2: 
        print lose
    elif computerwahl == 3: 
        print lose
    elif computerwahl == 4:
        print viktory
    else:
        print "Falsche Eingabe!"
def player_echse(computerwahl):
    if computerwahl == 0: 
        print lose
    elif computerwahl == 1: 
        print viktory
    elif computerwahl == 2: 
        print lose
    elif computerwahl == 3: 
        print tie
    elif computerwahl == 4: 
        print viktory
    else:
        print "Falsche Eingabe!"
def player_spook(computerwahl):
    if computerwahl == 0: 
        print viktory
    elif computerwahl == 1: 
        print lose
    elif computerwahl == 2: 
        print viktory
    elif computerwahl == 3: 
        print lose
    elif computerwahl == 4: 
        print tie
    else:
        print "Falsche Eingabe!"



if computerwahl == 0: 
    playerwahl
    print "Gegner wählt", computerwahl +1
    player(playerwahl, computerwahl)
elif computerwahl == 1: 
    playerwahl
    print "Gegner wählt", computerwahl +1
    player(playerwahl, computerwahl)
elif computerwahl == 2: 
    playerwahl
    print "Gegner wählt", computerwahl +1
    player(playerwahl, computerwahl)
elif computerwahl == 3: 
    playerwahl
    print "Gegner wählt", computerwahl +1
    player(playerwahl, computerwahl)
elif computerwahl == 4: 
    playerwahl
    print "Gegner wählt", computerwahl +1
    player(playerwahl, computerwahl)
else:
    print("error")

Kommentare:

Für diese Lösung gibt es noch keinen Kommentar

Bitte melden Sie sich an um eine Kommentar zu schreiben.
Kommentar schreiben