8

In addition to what @Reinderien mentioned, here are a few things I noticed. It would be beneficial to store the players and ratings in a more meaningful format PLAYERS = [ Player(name, rating) for name, rating in [ ('Jimmy', 600), ('Samie', 900), ('Elani', 400), ('Aron', 700), ('Emir', 1000), ('Sven', 1100), ('Nelson', ...


6

Use immutable sequences Turn NAMES = ['Jimmy', 'Samie', 'Elani', 'Aron', 'Emir', 'Sven', 'Nelson', 'Antonio', 'Isabel', 'Wally', 'Li', 'Noam', 'Francis', 'Danya', 'Danny', 'Engine'] RATINGS = [600, 900, 400, 700, 1000, 1100, 1300, 1500, 1600, 1800, 2000, 2200, 2300, 2650, 2500, 1000] into tuples instead of ...


3

Your current way of pairing players is \$O(n^2)\$ due to using the remove method. Each remove is \$O(n)\$ since all the values that come after the removed value need to be moved back 1 index position. To make the whole function \$O(n)\$, you could use random.shuffle instead of random.choice. You could do something like: random.shuffle(self.players) for n in ...


2

Your option1 and option2 functions are a bit confusing in that they use val_am, but up until that point, val_am hasn't been assigned yet. This forces me to read ahead a bit then scroll back a bit if I'm trying to follow the data, and also opens up the possibility of accidentally calling one of those two function before val_am has been set if you refactor ...


2

Do not write trivial getters/setters; this is not Java/C++/etc. It's more Pythonic to simply have everything public under most circumstances. Private-ness is not enforced anyway and is more of a suggestion. Consider using @dataclass You can drop empty parens after your class definition Under what circumstances would it be possible for properties to be ...


2

I think your current code is working- it seems like it’s getting the same answer as other people who say they solved it (i.e. 23514624000). So I think it belongs here. Right now, if you wanted to use this for any string of digits and any length of consecutive numbers, it would be \$O(n^2)\$ time complexity because you would have to multiply at most (length-...


2

I suggest to refactor it as follows: import random def guess_number (answer): for num_tries in range(5): try: guess = int(input("Your guess: ")) except: break if guess < answer: print ("Too low") elif guess > answer: print ("Too high") ...


2

This might seem a bit much, but I'm reviewing this as if it were intended for production code: black and isort can reformat this code to be more idiomatic without changing the functionality. pylint, flake8 or both can tell you of some issues with this code: $ pylint --disable=missing-function-docstring,missing-module-docstring q.py ************* Module q ...


2

How do you describe this function / math problem? The input is a list of tests with the same duration. For example, \$input=[2,2,2,2]\$. Given the indexes from 0 to 3, we can see it in a graph: So we can define the input as a (discrete) function \$f(x)=2\$, or in general \$f(x) = seconds/tests\$. Where \$0<=x<=tests,x∈Z\$. The function \$...


1

In Python, you don't need to create your variables before using them, so the address = '' before your loop is unnecessary. You also don't need to reset a variable before using it again, so the address = '' at the end of each loop iteration is particularly unnecessary. You currently get the addresses from the DB and then concatenate parts of that address as ...


1

Right now the program will have a problem if you use a word which has the same letter more than once. string.index will only return the index of the first occurrence. What you could do instead is use a set to check what letters still need to be guessed. If a character in the word is still in the set, it hasn’t been guessed and an underscore should be printed....


1

In terms of chess you seem to have missed some things (in addition it would be rare with such a tournament) that will require updates in the logic: If the number of players is not a power of two (there is likely to be some no-show) you will fail in make_pair as you will have an odd number of players and select one player and then not have an opponent. I ...


1

Are there likely to be some negative consequences of this decision? Absolutely. Calling help(DocumentObject) will not tell you what Property attributes exist in your class. An IDE won't have any information for autocomplete. Eg) Typing brick. and pressing the <TAB> key won't offer length and width as possible completions. Callers can add, remove and ...


1

This first, superficial refactor does the following: Rearrange functions in order of dependency Represent the return value of get_multipliers as a range and not a list for greater efficiency You're accepting a fraction, not a percentage; your inputs are -1 through 1, not -100 through 100 some minor variable name abbreviations convert duration_spread to a ...


1

What I have to add here, is that you should always validate/sanitize user input. guessing = int(input("Your guessing is? ")) Converting plain user input to an int, without checking, is prone to cause problems. I would suggest creating an isInteger(something: str) (something will always be a string) function to validate that. def safeInt(something:...


1

Validation This function _is_player_id_list_valid is stuck between two useful concepts - validating and returning bool, and throwing-or-not. Don't attempt to do a half-measure of both. Given its current name, it would be less surprising to do for player_id in provided_player_id_list: if player_id not in all_player_id_list: return False return ...


1

Unless I missed a major announcement regarding very new versions of Python, this isn't a proper type hint: def divide(parts: [str]) -> int: To type-hint a list, you need one of: from typing import List def divide(parts: List[str]) -> int: # Python 3.5+ def divide(parts: list[str]) -> int: # Python 3.9+ You have another bug as well: for e in ...


1

I think you overengineered this solution. Below is a barebones implementation in one file. The focus here is on keeping the runtime logic as simple as possible. That is, if you wanted a more robust system for adding operations, it should ideally still compile into a simple structure like a dictionary of operations before the calculator even begins. from ...


1

I think this is a strange use of the path library: "/" + path.join('sys', 'class', 'leds', 'system76_acpi::kbd_backlight') + '/' It would be clearer as a single string, given that we don't need portability to non-Linux hosts: '/sys/class/leds/system76_acpi::kbd_backlight/'


1

one major suggestion - don't (over)use global variables, it's generally not a good practice and it will make more difficult to test the code. And for example you'd like to add a functionality for downloading multiple items at the same time you'll have a hard time with it. So instead of this: def av_select(): global av_switch # this function is setting ...


Only top voted, non community-wiki answers of a minimum length are eligible