-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5848 from drifterDev/patch-30
Reto #45 - Python
- Loading branch information
Showing
1 changed file
with
82 additions
and
0 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
Retos/Reto #45 - EL CALENDARIO DE ADEVIENTO 2023 [Fácil]/python/drifterDev.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |