New answers tagged

0 votes

Determine a diver's table and schedule based on depth and duration

Use better program structure If your code is starting to look repetitious, you can think about subroutines. In this application, you are interpreting a table according to a set of rules. Since your ...
user avatar
  • 1,188
2 votes

Small shopping cart application - Solid Principles and Clean Code

I see no need for abstract classes here - there are no alternate implementations. This string: " Name: %s \n Price: %s \n" % (self.name, self.price) has ...
user avatar
  • 49.6k
5 votes

Check how many days a country has been independent

Delete all of your comments. None of them make the code more obvious than just reading it. strftime is unused so don't import it. Consider using a dictionary of ...
user avatar
  • 49.6k
1 vote

Compare files by name in two folders A and B and delete duplicates from folder A

The first "duplicates" line should read duplicates, *_ = groups = [files[0] , files[1]] my extended code move to trash - instead of delete ...
user avatar
  • 11
2 votes

Comma code project from "Automate the Boring Stuff with Python"

...
user avatar
  • 30.8k
-1 votes
Accepted

Forecast experimental results based on temperature

Your data are misshapen. Rather than having a separate Temp_ column per... what are those (10, 15, etc.)? Temperatures? There should be an index level per ...
user avatar
  • 49.6k
3 votes

MATLAB / vs Python np.linalg.solve, heat diffusion

Can you please tell me why Python is an order of magnitude slower for only even linear solve? Answering this generically is perhaps a little off-topic for review, but: first, it's important that we ...
user avatar
  • 49.6k
2 votes

Removing medications older than 180 days ago from a list

Bugs The code has at least two bugs. The first is when two adjacent list items are more than 6 months old, the second one will not be deleted. This occurs because when an item is deleted, the rest of ...
user avatar
  • 9,130
3 votes

Comma code project from "Automate the Boring Stuff with Python"

Don't use try-except blocks casually or excessively. You don't need them in the current case. And when exception handling is truly needed, you should restrict its use to the narrowest possible scope --...
user avatar
  • 10.1k
3 votes
Accepted

Credit Card Validation Check (Using Luhn's Algorithm)

Your program and functions are structured ineffectively. You have some code at the top level (collecting user input and converting it to numbers), then most of the ...
user avatar
  • 10.1k
3 votes

Removing medications older than 180 days ago from a list

Use a list comprehension! When constructing lists in python by looping through others lists, its a lot more visually de-cluttered (not necessarily more performant) to just use python's list ...
user avatar
-1 votes

Removing medications older than 180 days ago from a list

Depends on how much you care about performance. If you really care, don't use Python. If you kind of care, use Pandas in Python. I cannot speak to how you load your data in Pandas because you haven't ...
user avatar
  • 49.6k
3 votes

My 1 Week Python Journey — A Quiz Game that I made in Python

8-10 days aren't much and it gets the job done without any obvious errors so yeah that's ok. The efficiency of the program is mostly a concern if you're doing stuff that is computationally heavy and ...
user avatar
  • 131
2 votes
Accepted

Get some cryptocurrency rates from coingecko api

First, PEP8 suggests using snake_case instead of camelCase for regular variable names, so you should rename those. ...
user avatar
5 votes

How can I make my Pygame Tic Tac Toe game better?

These points are in order of how I went through your program. They are not ordered in matter of importance. Your code is suspicious from the start: ...
user avatar
  • 12.7k
3 votes
Accepted

Multi stage Dockerfile for eccode compilation

Instead of a COPY + RUN tar, you can get Docker to do the extraction for you by using ADD, ...
user avatar
  • 901
0 votes
Accepted

Speeding up row insertion to Pandas DataFrames

Without knowing what info['participants'] looks like, I've made this assumption. As others have mentioned it would help the reviewers if you could provide a small ...
user avatar
0 votes

Speeding up row insertion to Pandas DataFrames

...
user avatar
  • 27
3 votes

Multi stage Dockerfile for eccode compilation

Minor: tar -xzf eccodes-2.24.2-Source.tar.gz can simply use tar xf as the z is implied by ...
user avatar
  • 49.6k
12 votes

My 1 Week Python Journey — A Quiz Game that I made in Python

How is my progress so far (~8-10 days of learning)? Progress is non-linear, and technical learning is a long, long road (years-scale, not days-scale). So it's impossible to assess like this, but &...
user avatar
  • 49.6k
16 votes

My 1 Week Python Journey — A Quiz Game that I made in Python

Welcome to your journey in programming and in Python, I think that these 2 main concepts will help you improve to the next level: Functions as computations with an output rather than control flow ...
user avatar
  • 27.2k
1 vote

Guessing the Number Game

As you said, you are using PyCharm for writing Python code. Using this IDE, it only takes a single keyboard shortcut to make your code conform to large parts of PEP 8, which is the Python style guide. ...
user avatar
1 vote
Accepted

Simple backup script with file removal after 7 days

For many of your file manipulation operations prefer pathlib over os. You can pull in your filename formatting including time to ...
user avatar
  • 49.6k
2 votes

Guessing the Number Game

Underlining the structural advices of AJNeufeld: Structure helps to break down logic and express this organization visually, so that your code gets easier to read. I will try to illustrate the ...
user avatar
  • 785
3 votes
Accepted

Weighted Union-Find class

Documentation Docstrings are for users of the class. Docstrings should explain what is being done and returned. Currently your docstrings explain how it is being done, which should be comments. ...
user avatar
1 vote

Coin partitions

The readability is fine. If you cut out the documentation it's about 15 lines long, and short is almost always readable. Replace coins.sort with ...
user avatar
1 vote

3 dimensional python battleship game

The biggest problem with this code is readability. The actual program looks well-structured (good functions, reasonable use of classes, use of appropriate libraries, etc). There are a large number of ...
user avatar
7 votes

Guessing the Number Game

White Space Your code needs some. Specifically, blank lines between logical sections of code. between imports and function definitions Between function definitions After the last function definition ...
user avatar
  • 30.8k
0 votes

12 hour to 24 hour time conversion

In production code you would never manually parse a datetime like that. Instead you would use a round-trip through the datetime built-in: ...
user avatar
  • 49.6k
10 votes

Guessing the Number Game

Congrats for starting on your journey! Python is a great start to get into programming. And you got your very first project working! I can see that you used the basic elements of programming languages,...
user avatar
  • 651
1 vote
Accepted

12 hour to 24 hour time conversion

Program structure timeconversion is not a very descriptive function name. What is it converting from, and what is it converting to? I suggest ...
user avatar
1 vote

Fantasy game inventory — Ch. 5 Automate the Boring Stuff

I'm doing this in June 2022 but I don't think the problem asks for plurality for the values. In the example given, all the values are worded singularly. However if you want to go one step further to ...
user avatar
0 votes

Program for creating custom directory listings

You care about state of the art: that's good! But CGI and state of the art do not go in the same sentence. You're writing for integration to a specific server, Abyss, whose Python support explicitly ...
user avatar
  • 49.6k
1 vote
Accepted

Design Tic Tac Toe Interview Problem [Python 3]

This is an incomplete review up to the function TicTacToe.turn Re: ...
user avatar
  • 328
6 votes

Determine a diver's table and schedule based on depth and duration

Pandas was built for this kind of thing, and you can likely get your 700+ line program down to 30 lines of Python and a CSV file. You need to eliminate all of the repetition in your code, pull out the ...
user avatar
  • 49.6k
4 votes
Accepted

Design Shopping Cart System Interview Problem [Python 3]

Broadly speaking this does a lot of things right: self-written exceptions, (the start of) type hinting, overridden __str__, etc. ...
user avatar
  • 49.6k
5 votes

Implementation and Testing of Exponential Search for scenario where we search the same array/list many times

(Exponential Search is an improvement over binary search where the target can be expected to be close to some starting point.) class ExpSearch does not have a ...
user avatar
  • 4,548
3 votes
Accepted

Adding string to a text file without duplicates

You could make some improvements: Open the file just once in read+update mode. Instead of current_id_list, use a set, which can test whether an item is one of the ...
user avatar
2 votes

One of my first Python projects - an adventure game

This could be a place to implement a state machine. For such simple program, I would use globals to store the game state. (Unless you want to host multiple sessions at once in one process.) I would ...
user avatar
  • 149
3 votes

One of my first Python projects - an adventure game

As already mentioned by others, the branch conditions will get out of control quickly. It may be more suitable to encode the storyline in a separate file, such as a JSON file. Therefor we can identify ...
user avatar
7 votes

One of my first Python projects - an adventure game

Since you don't wait between prints, you can join some of them. Use triple quotes to extend a string on multiple lines (can be used for comments too) and \n to make a line break. ...
user avatar
1 vote

One of my first Python projects - an adventure game

Just a little tip on this line : start = input("Do you wish to begin your adventure? ").lower() When I tried your game, I just hit enter and it ...
user avatar
  • 11
10 votes

One of my first Python projects - an adventure game

Too much code duplication. Consider: ...
user avatar
  • 30.8k
1 vote

One of my first Python projects - an adventure game

Right off the bat, instead of strings maybe it'd be better to prompt your users to input the option number instead. It'd probably be cleaner, less prone to user error and allow you to run a Switch ...
user avatar
4 votes
Accepted

Calculate the number of people occupied at each time interval

Generally, at the edge of your program you shouldn't be entering datetimes as timestamp numeric literals, but as human-legible datetimes. On the inside of your program, you also shouldn't be ...
user avatar
  • 49.6k
1 vote

Password policy with regex and zxcvbn

Elevate the data that drives the code to the status of named constants. Among other benefits, this simple change will support any efforts you might make to subject the code to automated testing (...
user avatar
  • 10.1k
9 votes

Measure the total runtime of a function in a project

The already accepted answer by Dair is better than what I am about to write here, however I think there is didactic value in trying to improve the code as written, so consider this a supplementary ...
user avatar
  • 356
2 votes
Accepted

Calculates delivery charges and number of deliveries

Python has built-in support for showing localised currencies; you might as well use this. It shows to the nearest pence so you don't really have to use Decimal for ...
user avatar
  • 49.6k
4 votes

Password hashing for safe storage with Argon

Argon2 is a decent choice of hash. Well done for following the most important rule of cryptography, and letting someone else design and implement the cryptography! There are a few minor style things ...
user avatar
  • 5,721
14 votes
Accepted

Measure the total runtime of a function in a project

Adressing the question: Is there already a solution like this in the standard libs? Unless I am misinterpreting what you want exactly, there are profiling tools available in the standard library. ...
user avatar
  • 5,754

Top 50 recent answers are included