Conversation
1] guessing game/main.py
Outdated
| print("Too big number...") | ||
| continue | ||
| else: | ||
| return "!!! YOU WIN !!!" |
There was a problem hiding this comment.
v returnu ten string nevracet - tim spis kdyz delas typing a rikas ze ta funkce ma vratit int
There was a problem hiding this comment.
Rozumím, ten typing jsem tam zapomněla. Takže správné řešení bude smazat ten typing a do returnu dát proměnou, která obsahuje tuhle zprávu?
There was a problem hiding this comment.
udelej proste print("u win") a return
a typing bude None
| # getting a number of player | ||
| while True: | ||
| try: | ||
| player_num = int(input("Enter whole number: ")) |
There was a problem hiding this comment.
ten try je zbutecne velky, idealne je obalit jen tu cast kodu kde cekas tu vyjimku
There was a problem hiding this comment.
Opraveno, jak dodělám všechny opravy, postnu.
2] loto/main.py
Outdated
| Funktion return a sorted list of numbers. | ||
| """ | ||
| # gettint a list of numbers | ||
| player_nums = [] |
There was a problem hiding this comment.
lepsi je set protoze delas memebership test s pouzitim in operatoru. Set je na tuhle operaci lepe staveny, ma konstatni casovou komplexitu pro ziskani prvku, zatimco list linearni - ty listy jsou tady kratke ale i tak je set vzdy lepsi
2] loto/main.py
Outdated
| The function uses randint() and gets a list | ||
| of six original numbers in the range 1-49. | ||
| """ | ||
| draw_nums = [] |
There was a problem hiding this comment.
tady by byl lepsi taky set, ze stejneho duvoadu jako vyse
2] loto/main.py
Outdated
|
|
||
| # evaluation of results | ||
| hits = 0 | ||
| for num in player_nums: |
There was a problem hiding this comment.
tady pak delas dvojity loop prave proto, ze mas ty data v listech a ne v setech. Takze tohle pobezi v kvdardatickem case zatimco kdyzbys mela sety tak muze bezet v linernim case.
jak rikam, ty listy jsou tu male, takze to tolik nevadi, ale obecne kdyz mas v kodu IN tak je lepsi to chcekovat oproti setu
| return answer | ||
| else: | ||
| print("Wrong value, try again...") | ||
| get_answer() |
There was a problem hiding this comment.
to delas rekurzivne jo? to je teda fikany :) Potencialne se ti ale muze stat, ze na to crashne cely program kdyz bude nekdo dostatecne dlouho zadavat chybne hodnoty, protoze se bude kupit kupit rekurzivni volani funkci na sebe a to ma nejkay limit
There was a problem hiding this comment.
Jj, učili mě, že se máme vyvarovat tomu, abychom psali stejný kód více krát, tak mi to přišlo nejjednodušší. Mám to přepsat?
There was a problem hiding this comment.
no to bys mela. anebo musis osetrit ze to nevyhodi eror.
ale to nemusi opakovat. Staci to misto do rekurze dat do loopu preci
3] guessing game 2/main.py
Outdated
|
|
||
| while num_of_tries: | ||
| # calculation of the quessed number | ||
| guess = int((max-min) / 2) + min |
There was a problem hiding this comment.
ne cast na int, ale udelat flor div //
| num_of_tries -= 1 | ||
| elif answer == "you quessed": | ||
| print("I won!") | ||
| num_of_tries = 0 |
There was a problem hiding this comment.
pracovat s numer of tries a mit to jako kontrolni promenou v loopu je trochu divny - proc to delas takhle?
There was a problem hiding this comment.
Přijde mi to nejkratší podmínka pro while, aby vracela True, pokud má hráč ještě pokusy a False, pokud je už vyčerpal. V téhle části jsem zvažovala, jestli nepoužít break, ale použití num_of_tries = 0 mi přišlo pro ostatní čtenáře mého kódu čitelnější, že se pořád držím stejného principu, že jestli while loop jede závisí na téhle proměnné.
There was a problem hiding this comment.
ne, to neni ze ma pokusy nebo vycerpal
ten algortmus sam o sobe zajisti, ze nemuze prekrocit 10 pokusu na 1000 protoze bezi v logaritmicke komlexite a log(1000) = 10.
ty tam vubec tohle nemas kontrolovat
4] guessing game 3/main.py
Outdated
| guess = 0 | ||
|
|
||
| def calculation(minimum=int, maximum=int) -> int: | ||
| return int((maximum-minimum) / 2) + minimum |
4] guessing game 3/main.py
Outdated
|
|
||
| @app.route("/too_low", methods=["GET", "POST"]) | ||
| def too_low(): | ||
| global min_num, max_num, guess |
There was a problem hiding this comment.
uff .. gobalni promenne jsou dost bad practise, to se moc neuc. To se dela opravdu jen v pripadech kde se musi neco hodne ohnout.
There was a problem hiding this comment.
Chápu, je mi jasný, že je to řešení poněkud na čuňátko... ale já prostě nemohla přijít na to, jak jinak to udělat. Neměl bys prosím nějakou radu?
There was a problem hiding this comment.
no ja myslim ze mas hlavne udelat jen jedno tu routu @app.route("/", methods=["GET", "POST"])
a v ni mit celou tu logiku, ktera je v podstate stejna jako v tom predeslem ukolu, jenom je to obalene do HTML.
5] 2001/main.py
Outdated
| math_mark = "" | ||
|
|
||
| # first format check | ||
| if "D" not in entered_value: |
There was a problem hiding this comment.
cela ta logika na parsovani vstupu je super komplextni :)
to jde udelat celkme jednoduse pres regex
There was a problem hiding this comment.
O Regex slyším prvně, to se teď hned nestihnu doučit, tak jsem opravila bez toho.
5] 2001/main.py
Outdated
| # first split + additional check | ||
| first_cut = entered_value.split("D") | ||
| if len(first_cut) != 2: | ||
| return error_allert |
There was a problem hiding this comment.
proc vraci nejaky string? normalne vyhod vyjimku
5] 2001/main.py
Outdated
| math_mark = "+" | ||
| second_cut = second_cut_check(first_cut[1], math_mark) | ||
| if second_cut == None: | ||
| return error_allert |
There was a problem hiding this comment.
ojojoj tady je trojite zanoreni.. to je opravdu velmi velmi komplikovane. ttakle to nemuzes delat
| Pokud ano, vrátí hodnotu hodu za použití funkce | ||
| calculation(). Pokud ne, vrátí chybové hlášení. | ||
| """ | ||
| error_dice = "WRONG DICE: a correct dice - D3, D4, D6, D8, D10, D12, D20, D100" |
There was a problem hiding this comment.
takle se to ale nedela nejake errory, k tomuhle s epouzivaji vyjimky.
| Pokud ano, vrátí hodnotu hodu za použití funkce | ||
| calculation(). Pokud ne, vrátí chybové hlášení. | ||
| """ | ||
| error_dice = "WRONG DICE: a correct dice - D3, D4, D6, D8, D10, D12, D20, D100" |
There was a problem hiding this comment.
takle se to ale nedela nejake errory, k tomuhle s epouzivaji vyjimky.
| try: | ||
| rolls = int(first_cut[0]) | ||
| except ValueError: | ||
| return error_value |
There was a problem hiding this comment.
tady bys mela spis napsat raise a vyhodit nejakou tu vyjimku
|
|
||
| # výpočet hodu s modifikátorem | ||
| if modifier: | ||
| return eval(str(calculation(rolls, dice)) + math_mark + str(modifier)) |
There was a problem hiding this comment.
neni potreba delat eval na string kdyz ti ta funkce vrti int se kterym jde hned pocitat
No description provided.