#🔒 Code review - match simulator
30 messages · Page 1 of 1 (latest)
@trim night
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
hey
def creer_equipe(nom: str) -> dict:
equipe = dict();
equipe["nom"] = nom;
equipe["joueurs"] = list();
equipe["Score"] = 0;
equipe["victories"] = 0;
equipe["vif"] = False;
return equipe;
``` you can do ```py
def creer_equipe(nom: str) -> dict:
return {
"nom": nom,
"joueurs": [],
# res of your keys here
}
``` for one
True!
if equipe1["vif"] == True or equipe2["vif"] == True:
if equipe1["vif"] == True and equipe2["vif"] == True:
``` can be ```py
if equipe1["vif"] or equipe2["vif"]:
if equipe1["vif"] and equipe2["vif"]:
why even repeat the same exact check?
oh right :D
why even repeat the same exact check?
It's the difference of or and and
oh right the and can be moved out
ah, didn't notice
buff = (1.0, 1.0, 1.0);
match meteo:
case "ensoleillé":
buff = (1.1, 1.1, 1.1);
case "nuageux":
buff = (1.0, 0.9, 1.0);
case "pluvieux":
buff = (0.9, 0.6, 0.8);
case "venteux":
buff = (0.8, 0.7, 0.9);
case "brumeux":
buff = (0.6, 0.5, 0.6);
``` you can use a dict here instead of match case
buffs = {
"ensoleillé": (1.1, 1.1, 1.1),
"nuageux": (1.0, 0.9, 1.0),
# rest of the buffs
}
buff = buffs.get(meteo, (1.0, 1.0, 1.0))
also i noticed you're looping over range(len(equipe["joueurs"])) many times just to access equipe["joueurs"][i], instead of that you can simply loop over equipe["joueurs"]
so for example
def diminuer_force(equipe: dict):
for i in range(len(equipe["joueurs"])):
if equipe["joueurs"][i]["force"] != 0:
equipe["joueurs"][i]["force"] -= 1;
``` becomes
```py
def diminuer_force(equipe: dict):
for elem in equipe["joueurs"]:
if elem["force"] != 0:
elem["force"] -= 1;
thats kind of all i see
Thxxx
Hmm but if I do that isn't elem not a reference to the original var?
:white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | a
002 | b
003 | c
``py
oops
!e
vals = [{'a': 0}, {'a': 2}, {'a': 4}]
for val in vals:
val['a'] += 1
print(vals)
:white_check_mark: Your 3.12 eval job has completed with return code 0.
[{'a': 1}, {'a': 3}, {'a': 5}]
so yes elem would be a reference
as opposed to what?
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.