On 14/06/16 11:18, Katelyn O'Malley wrote:
> Hi I am just getting into python and I am trying to create a rock paper
> scissor lizard spock game for 3 people and I cannot figure out the scoring

The scoring of any ganme is the bit that makes it unique, so we would
need to know the scoring rules to know how you should proceed. however
there are many things we could look at in your code, I will restrict
myself to one:

> def name_to_number(name):
>     if name == "rock":
>         name = 0
>         return name
>     elif name == "spock":
>         name = 1
>         return name
>     elif name == "paper":
>         name = 2
>         return name
>     elif name == "lizard":
>         name = 3
>         return name
>     elif name == "scissors":
>         name = 4
>         return name

This type of code can be greatly shortened and simplified by using
a more appropriate data structure, such as a dictionary:

def name_to_number(name):
    tokens = {"rock":0, "spock":1, "paper":2, "lizard":3, "scissors":4}
    return tokens[name]

And something very similar for the number_to_name function below.

HTH
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to