Skip to content

Commit

Permalink
Merge pull request #5848 from drifterDev/patch-30
Browse files Browse the repository at this point in the history
Reto #45 - Python
  • Loading branch information
Roswell468 authored Nov 24, 2023
2 parents c934848 + 4f6b9fe commit 5d6f955
Showing 1 changed file with 82 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import random

class App:
def __init__(self):
self.persons = []

def add(self, person):
if person not in self.persons:
self.persons.append(person)
return True
else:
return False

def delete(self, person):
if person in self.persons:
self.persons.remove(person)
return True
else:
return False

def lottery(self):
if len(self.persons) == 0:
return None
choice = random.choice(self.persons)
self.persons.remove(choice)
return choice

def show(self):
if len(self.persons) == 0:
print("No hay participantes")
return
print("Participantes:")
for p in self.persons:
print(p)

def main():
app = App()
menu = """
Selecciona una opcion:
1. Anadir participante
2. Eliminar participante
3. Mostrar participantes
4. Realizar sorteo
5. Salir
"""
while True:
print(menu)
try:
option = int(input("Opcion: "))
if option == 1:
name = input("Participante: ")
result = app.add(name)
if result:
print("Anadido")
else:
print("Paricipante ya existe")
elif option == 2:
name = input("Participante: ")
result = app.delete(name)
if result:
print("Eliminado")
else:
print("Participante no existe")
elif option == 3:
app.show()
elif option == 4:
result = app.lottery()
if result == None:
print("No hay participantes")
else:
print("El ganador del sorteo es:", result)
elif option == 5:
print("Adios")
break
else:
print("Opcion invalida")
except:
print("Opcion invalida")


if __name__ == "__main__":
main()

0 comments on commit 5d6f955

Please sign in to comment.