Skip to content

Workshop 03022024#5

Open
Diana-Prusova wants to merge 15 commits intoCodersLab-CZ:masterfrom
Diana-Prusova:workshop_03022024
Open

Workshop 03022024#5
Diana-Prusova wants to merge 15 commits intoCodersLab-CZ:masterfrom
Diana-Prusova:workshop_03022024

Conversation

@Diana-Prusova
Copy link

No description provided.

print("Too big number...")
continue
else:
return "!!! YOU WIN !!!"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v returnu ten string nevracet - tim spis kdyz delas typing a rikas ze ta funkce ma vratit int

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

udelej proste print("u win") a return
a typing bude None

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Děkuju, hotovo

# getting a number of player
while True:
try:
player_num = int(input("Enter whole number: "))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ten try je zbutecne velky, idealne je obalit jen tu cast kodu kde cekas tu vyjimku

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 = []

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opraveno

2] loto/main.py Outdated
The function uses randint() and gets a list
of six original numbers in the range 1-49.
"""
draw_nums = []

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tady by byl lepsi taky set, ze stejneho duvoadu jako vyse

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opraveno

2] loto/main.py Outdated

# evaluation of results
hits = 0
for num in player_nums:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opraveno

return answer
else:
print("Wrong value, try again...")
get_answer()
Copy link

@ExperimentalHypothesis ExperimentalHypothesis Feb 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no to bys mela. anebo musis osetrit ze to nevyhodi eror.

ale to nemusi opakovat. Staci to misto do rekurze dat do loopu preci


while num_of_tries:
# calculation of the quessed number
guess = int((max-min) / 2) + min

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ne cast na int, ale udelat flor div //

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opraveno

num_of_tries -= 1
elif answer == "you quessed":
print("I won!")
num_of_tries = 0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pracovat s numer of tries a mit to jako kontrolni promenou v loopu je trochu divny - proc to delas takhle?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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é.

Copy link

@ExperimentalHypothesis ExperimentalHypothesis Feb 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

guess = 0

def calculation(minimum=int, maximum=int) -> int:
return int((maximum-minimum) / 2) + minimum

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flor div //

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opraveno.


@app.route("/too_low", methods=["GET", "POST"])
def too_low():
global min_num, max_num, guess

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uff .. gobalni promenne jsou dost bad practise, to se moc neuc. To se dela opravdu jen v pripadech kde se musi neco hodne ohnout.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cela ta logika na parsovani vstupu je super komplextni :)

to jde udelat celkme jednoduse pres regex

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

takle se to ale nedela nejake errory, k tomuhle s epouzivaji vyjimky.

try:
rolls = int(first_cut[0])
except ValueError:
return error_value

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

neni potreba delat eval na string kdyz ti ta funkce vrti int se kterym jde hned pocitat

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants