8

Welcome to Code Review! I'll add to the other answer from Reinderien. PEP-8 In python, it is common (and recommended) to follow the PEP-8 style guide for writing clean, maintainable and consistent code. Functions and variables should be named in a lower_snake_case, classes as UpperCamelCase, and constants as UPPER_SNAKE_CASE. No unnecessary whitespaces are ...


7

Path? Surely path is not a single path, since you loop through it. So at the least, this is poorly-named and should be paths. The variable you iterate through it, fileName, should be file_name; similarly for your other function and variable names. Line iteration Rather than calling readlines(), simply iterate over file itself, which will have the same effect....


6

Your implementation seems fine at a glance, but Python actually provides two really easy ways to do this: string.format bin Your function would then become: def integer_to_binary_string(int_value): '''Converts integer to a string of base-2 bits, example: 20 becomes '10100' ''' return f"{int_value:b}" # or ...


5

Several general hints: Formatting: Use an auto-formatter. I recommend black. It's wide-spread, maintained by the Python Software Foundation, allows little configuration so the style is consistent among projects (no configuration is good in this case) Linting: Use linters. I recommend flake8 with flake8-bugbear, flake8-comprehensions, ...


5

According to PEP8, docstrings should use """ instead of ''' Both integer_to_reverse_binary and reverse_string are only used once. I'd just replace the usage with the body of the functions. Instead of integer_to_binary_string, I would prefer a shorter name such as int_to_bin. log2 is inaccurate for large values and should be avoided if ...


5

In addition to the points raised in the other answers: Extraneous import The first line is import sys, but I don't see sys used anywhere; this can go. Explicit naming It's generally better to use explicit names. Thus, rather than just seq (which might be short for sequence or sequences, for example) spell it out. In this case, it looks like you should use ...


3

I only have a few points to add to Dannnno's, Sriv's, and Martin Thoma's excellent answers. Consistency Sometimes, you abbreviate string as "str", sometimes as "s", sometimes not at all. Sometimes, you put the type in the identifier, sometimes not. When you put the type in the identifier, you sometimes put it as a prefix, sometimes as a ...


3

Consider fetch In modern browsers, which your code is guaranteed to be running in, fetch is usually a better choice than XMLHttpRequest - fetch is Promise-based (Promises are usually a bit nicer to work with than callbacks), its API is a bit cleaner to read and write, and it's a bit more concise. Error handling The front-end has no error handling. If the ...


1

Separation of Concerns Your function is doing too much. It is: Converting the float to a fraction Converting the fraction to a string of digits Printing the string of digits You should separate these. Float to Fraction First, let's move the float-to-fraction code into its own function. from typing import Tuple def float_to_fraction(value: float) -> ...


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