lundi 1 février 2016

What's wrong with this if elif else code in python?

I'm a newbie trying to get the hang of python. Right now I'm making a simple Rock, Paper, Scissor game. As you can see in my code, the program asks the user if they want to play best out of 3 or 5, if the input is 'five', '5' or 'cinco' the function "best_out_of_five()" executes (which is just '5555555' for now). Same thing with three and then I have a else which closes the program. My problem is that whatever input is read, it just executes the "best_out_of_five" function (even if the input is 'three'). I thought the if, elif and else would be the easiest part of my code since I have done it many times before, but I must be missing something that I just can't notice.

import time

    def best_out_of_three():
        print('333333333')

    def best_out_of_five():
        print('555555555')

    name = input("Hi, what's your name?\n")
    print('Alright', name + ", lets play a quick game of Rock, Paper, Scissors. Do you want to play best out of 3 or 5?")
    game_type = input().lower()
    if game_type == "five" or '5' or 'cinco':
        best_out_of_five()
    elif game_type == "three" or '3' or 'tres':
        best_out_of_three()
    else:
        print("That is not a valid answer. Try again later.")
        time.sleep(5)
        exit()

Aucun commentaire:

Enregistrer un commentaire