0

I was making a program on Python 3.4, which purpose is to make random draws among given football teams.

import random

modo = str(input("Sorteo o Simulación completa? "))
torneo = str(input("Torneo elegido: "))
fase = int(input("Número de equipos (en la fase a sortear): "))

 def sorteo(x,y):
     if x == "Champions" or "champions" or "shempions" or "Shempions" or "Uefa Champions League" and y == 32:
        bombo1 = str(input("8 equipos del primer bombo: ")).split(",")
        bombo2 = str(input("8 equipos del segundo bombo: ")).split(",")
        bombo3 = str(input("8 equipos del tercer bombo: ")).split(",")
        bombo4 = str(input("8 equipos del cuarto bombo: ")).split(",")
        names = ["A","B","C","D","E","F","G","H"]
        for i in range(8):
            grupo = []
            n = names[i]
            first = random.choice(bombo1)
            grupo.append(first)
            bombo1.remove(first)
            second = random.choice(bombo2)
            grupo.append(second)
            bombo2.remove(second)
            third = random.choice(bombo3)
            grupo.append(third)
            bombo3.remove(third)
            fourth = random.choice(bombo4)
            grupo.append(fourth)
            bombo4.remove(fourth)
            print("Grupo " + str(n) + ": " + str(grupo))
        return

 if x == "Champions" or "champions" or "shempions" or "Shempions" or "Uefa Champions League" and y == 16:
        primeros = str(input("8 equipos que quedaron primeros: ")).split(",")
        segundos = str(input("8 equipos que quedaron segundos: ")).split(",")
        for i in range(8):
            n = i + 1
            first = random.choice(primeros)
            primeros.remove(first)
            second = random.choice(segundos)
            segundos.remove(second)
            print("Cruce " + str(n) + ": " + str(first) + " VS " + str(second))
        return

 if x == "Champions" or "champions" or "shempions" or "Shempions" or "Uefa Champions League" and y == 8:
        equipos_cuartos = str(input("8 equipos que pasaron a Cuartos: ")).split(",")
        for i in range(4):
            n = i + 1
            first = random.choice(equipos_cuartos)
            equipos_cuartos.remove(first)
            second = random.choice(equipos_cuartos)
            equipos_cuartos.remove(second)
            print("Cruce " + str(n) + ": " + str(first) + " VS " + str(second))
        return

 if x == "Champions" or "champions" or "shempions" or "Shempions" or "Uefa Champions League" and y == 4:
        equipos_semis = str(input("4 equipos que pasaron a Semis: ")).split(",")
        for i in range(2):
            n = i + 1
            first = random.choice(equipos_semis)
            equipos_semis.remove(first)
            second = random.choice(equipos_semis)
            equipos_semis.remove(second)
            print("Cruce " + str(n) + ": " + str(first) + " VS " + str(second))
        return

if modo == "Sorteo" or "sorteo":
     sorteo(torneo,fase)

However, the result is always the same: No matter the amount of teams I select on "fase": It always ask me for bombo1,2,3 and 4 teams, like I always select 32 teams to participate. ANd if I ask this here is because I drove myself insane the whole yesterday and today in order to repair this, because this problem appears when I introduce more than one tournament and function too.

  • 2
    Possible duplicate of [How do I test one variable against multiple values?](http://stackoverflow.com/questions/15112125/how-do-i-test-one-variable-against-multiple-values) – Tadhg McDonald-Jensen May 17 '16 at 19:09
  • when you do `x == "Champions" or "champions"` it isn't the same as `if x == "Champions" or x == "champions"`, you either need to check `x` explicitly against each on or use the `in` operator. – Tadhg McDonald-Jensen May 17 '16 at 19:11

1 Answers1

0

The issue is in the way python is grouping the and y == #, it will only group it with the last condition, so in the case of the first if it will group it with or "Uefa Champions League" and y == 32. However, as others have said within the comments it will never get this far as you are checking or "champions", which is True because any non-empty "" string is considered True. So you will need to explicitly check all of the values against x and also group them so that your y == # will also check when either of the conditions is True.

As suggested, I would use something like the following:

if x in {"Champions", "champions", "shempions", "Shempions", "Uefa Champions League"} and y == #:

Cory Shay
  • 1,204
  • 8
  • 12