Mine værktøjer
Du er her: Forside Python program eksempler. sten saks papir

sten saks papir

Tilbage

Hent filen

Licens GPL

Rock, Paper, and Scissors

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#
import random
Language = "English"
PHRASES = {
    "English":{
        "Language":"E) Choose english",
        "WIN":'You won!',
        "LOSE": 'You Lose!',
        "DRAW": 'Draw!',
        "BYE": 'Se you later',
        "r":"ROCK",
        "s":"SCISSORS",
        "p":"PAPER",
        "Computer":"Computer",
        "You":"You",
        "choosetext":"Please write firstletter",
        "leavetext":"anything else exit program",
        "choices": ['r', 's', 'p'],
        "choicetext": "Rock, Scissors or paper",
        },
    "Danish":{
        "Language":"D) Vælg dansk",
        "WIN":'Du vandt!',
        "LOSE": 'Du tabte!',
        "DRAW": 'Uafgjort!',
        "BYE": 'Vi ses',
        "s":"Sten",
        "a":"sAks",
        "p":"Papir",
        "Computer":"Computer",
        "You":"Dig",
        "choosetext":"Tast det store bogstav",
        "leavetext":"alt andet sluttet programmet",
        "choices": ['s', 'a', 'p'],
        "choicetext": "Sten, sAks eller Papir",
        },
    }


for Language in PHRASES.keys():
    print  PHRASES[Language]["Language"]

Lang = raw_input(':')
for Language in PHRASES.keys():
    if PHRASES[Language]["Language"].startswith(Lang):
        break # Language found

Values = PHRASES[Language]
choice = PHRASES[Language]["choices"][:]

Format = "%(Computer)s: %%s %(You)s: %%s : %%s\n" % Values
def translate(choice,language):
    if language == "English":
        return choice
    Echoice = PHRASES["English"]["choices"]
    Lchoice = PHRASES[language]["choices"]
    if choice in Lchoice:
        return Echoice[ Lchoice.index(choice)]
    return choice


def winner(a,b,language):
    """ if a wins return true else return false """
    if a == b:
        return "DRAW"
    a = translate(a, language)
    b = translate(b, language)
    if a == "r" and b == "s" or a == "s" and b == "p" or a == "p" and b == "r":
        return "WIN"
    return "LOSE"


def getAnswer():
    return raw_input('%(choosetext)s %(choicetext)s %(leavetext)s: ' % Values).strip().lower()



userselection = getAnswer()
while Values.has_key(userselection):
    random.shuffle(choice)
    print Format % ( Values[choice[0]], Values[userselection], Values[ winner(userselection,choice[0], Language) ])
    userselection = getAnswer()

print Values["BYE"]


« august 2018 »
søn man tir ons tor fre lør
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Chat Rooms
Dyrk motion

Trim ballerup

 

Powered by Plone, the Open Source Content Management System